What is the ch_reserved field in Elf64_Chdr used for?

32 views
Skip to first unread message

H.J. Lu

unread,
Sep 21, 2015, 11:32:45 AM9/21/15
to Generic System V Application Binary Interface
gABBI has

typedef struct {
Elf32_Word ch_type;
Elf32_Word ch_size;
Elf32_Word ch_addralign;
} Elf32_Chdr;

typedef struct {
Elf64_Word ch_type;
Elf64_Word ch_reserved;
Elf64_Xword ch_size;
Elf64_Xword ch_addralign;
} Elf64_Chdr;

What is ch_reserved used for? I didn't notice it when I implemented
the compression support in binutils. My Elf64_Chdr only has

typedef struct {
unsigned char ch_type[8]; /* Type of compression */
unsigned char ch_size[8]; /* Size of uncompressed data in bytes */
unsigned char ch_addralign[8]; /* Alignment of uncompressed data */
} Elf64_External_Chdr;


--
H.J.

H.J. Lu

unread,
Sep 21, 2015, 11:36:49 AM9/21/15
to Generic System V Application Binary Interface, Ali.B...@oracle.com
On Mon, Sep 21, 2015 at 8:32 AM, H.J. Lu <hjl....@gmail.com> wrote:
> gABBI has
>
> typedef struct {
> Elf32_Word ch_type;
> Elf32_Word ch_size;
> Elf32_Word ch_addralign;
> } Elf32_Chdr;
>
> typedef struct {
> Elf64_Word ch_type;
> Elf64_Word ch_reserved;
> Elf64_Xword ch_size;
> Elf64_Xword ch_addralign;
> } Elf64_Chdr;
>
> What is ch_reserved used for? I didn't notice it when I implemented
> the compression support in binutils. My Elf64_Chdr only has

Is it a typo? Shouldn't it be

typedef struct {
Elf32_Word ch_type;
Elf32_Word ch_reserved;
Elf64_Xword ch_size;
Elf64_Xword ch_addralign;
} Elf64_Chdr;

Ali Bahrami

unread,
Sep 21, 2015, 12:07:50 PM9/21/15
to H.J. Lu, Generic System V Application Binary Interface
Hi HJ,

It's to force the layout of the Elf64_Chdr struct
be identical on all platforms. Recall that the 32-bit
x86 ABI can allow 64-bit integers to be accessed on
32-bit boundaries. By explicitly labeling the "hole"
in this struct and pinning it down, we're preventing
that from happening.

I don't think the use of Elf64_Word is a typo, though
I do see why it's confusing. Note that Elf32_Word and
Elf64_Word are both defined as 32-bit unsigned integers,
so they're really the same type. It seemed appropriate
to use the Elf64 form within another Elf64 typedef.

Given that Elf32_Word and Elf64_Word are the same type,
we could ask why it's not just Elf_Word. I wasn't there,
but one reason might have been to open the door for
Elf128_Word to be a larger quantity if and when we find
ourselves at that threshold.

- Ali

Suprateeka R Hegde

unread,
Sep 21, 2015, 2:00:31 PM9/21/15
to gener...@googlegroups.com
Or could it be as follows?

Going by the existing convetions, "Elf*_Word" seems to mean the "Full
Integer" size for that model.

Based on the famous 64-bit programming model -- LP64, the full integer
is still 32 bits. And hence Elf64_Word is also 32 bits. And for all the
64 bit support, we have Elf64_Xword or Elf64_Sxword.

Or in other words, it might be just a naming convetion:
Elf32_Word means size of Full Integer on ILP32 model.
Elf64_Word means size of Fulll Integer on LP64 model.

However, the confusion is still there for other modles as the gABI
document specifies the size too. If the size was not specified and only
the type was specified, then each model could gets its own meaning.

In that way, as Ali said, Elf_Word might have been enough and that would
mean whatever is the size of full integer on that model. For this to
happen, we should remove the size attribute and just keep the type.

--
Supra

Ali Bahrami

unread,
Sep 21, 2015, 2:48:25 PM9/21/15
to gener...@googlegroups.com
On 09/21/15 12:00, Suprateeka R Hegde wrote:
> Or could it be as follows?
>
> Going by the existing convetions, "Elf*_Word" seems to mean the "Full Integer" size for that model.
>
> Based on the famous 64-bit programming model -- LP64, the full integer is still 32 bits. And hence Elf64_Word is also 32 bits. And for all the 64 bit support, we have Elf64_Xword or Elf64_Sxword.
>
> Or in other words, it might be just a naming convetion:
> Elf32_Word means size of Full Integer on ILP32 model.
> Elf64_Word means size of Fulll Integer on LP64 model.
>
> However, the confusion is still there for other modles as the gABI document specifies the size too. If the size was not specified and only the type was specified, then each model could gets its own meaning.
>
> In that way, as Ali said, Elf_Word might have been enough and that would mean whatever is the size of full integer on that model. For this to happen, we should remove the size attribute and just keep the type.


It is, as you suggest, a naming convention. Elf*_Word
means simply, the definition of Word applicable to ELFCLASS*.
It does not mean "full integer" or anything like that, which
is why the gABI also specifies the size.

The fact that Elf64_Word is a 32-bit value was a well understood and
intentional decision made when ELFCLASS64 was defined, and not one
that can be reasonably changed now. I was speculating about other
ways this might have been defined, but I shouldn't have because it's
history, and it's done, and really, it's fine.

I should have just said: Elf64_Word is the right type to use
in defining Elf64_Chdr, because it's the ELFCLASS64 Word
type, and as it's defined to be a 32-bit integer, will have
the desired effect on structure layout.

Thanks...

- Ali

Reply all
Reply to author
Forward
0 new messages