Clear up confusion on elf32 vs elf64 notes which in fact are the same#36
Open
wanders wants to merge 1 commit intocole14:masterfrom
Open
Clear up confusion on elf32 vs elf64 notes which in fact are the same#36wanders wants to merge 1 commit intocole14:masterfrom
wanders wants to merge 1 commit intocole14:masterfrom
Conversation
c4b6b0f to
f0ecb8a
Compare
At least linux, freebsd and llvm headers define Elf32_Nhdr: Elf32_Word n_namesz; Elf32_Word n_descsz; Elf32_Word n_type; and Elf64_Nhdr as: Elf64_Word n_namesz; Elf64_Word n_descsz; Elf64_Word n_type; Both Elf32_Word and Elf64_Word correspond to u32 (Half, Word, Xword types are the same for Elf32 and Elf64, while types such as Addr and Off differ). Note (no pun intended) that this contradicts System V Application Binary Interface - DRAFT - 24 April 2001 which says: > Note Section > ... > The note information in sections and program header elements holds a > variable amount of entries. In 64-bit objects (files with > e_ident[EI_CLASS] equal to ELFCLASS64), each entry is an array of > 8-byte words in the format of the target processor. In 32-bit objects > (files with e_ident[EI_CLASS] equal to ELFCLASS32), each entry is an > array of 4-byte words in the format of the target processor. Labels > appear below to help explain note information organization, but they > are not part of the specification. But according to SysTools.Elf from GHC https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/SysTools/Elf.hs#L81 "nobody" does that: > In practice, for almost all platforms namesz, descz and type fields > are 4-byte words for both 32-bit and 64-bit objects (see elf.h and > readelf source code). > > The only exception in readelf source code is for IA_64 machines with > OpenVMS OS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The definitions of note sections (and segments) for Elf32 and Elf64 is a bit of a mess. There is a specification saying Elf64 should use 8-byte fields. But noone does that.
(The alignment may however differ, but that is a different thing)
N.B this changes the type of the publically visible
NoteAny.n_typeSources
linux
LSB elf.h says Elf32_Nhdr and Elf64_Nhdr are identical:
https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/libc-ddefs.html
But also in Executable And Linking Format (ELF) refers to "System V ABI Update" which specifies it as using 8-byte fields for namesz, descsz and type.
freebsd
Elf32_Nhdr
https://github.com/freebsd/freebsd-src/blob/b9a60d36ba043f313ab98b8dd058d49559254791/sys/sys/elf64.h#L172
and Elf64_Nhdr
https://github.com/freebsd/freebsd-src/blob/b9a60d36ba043f313ab98b8dd058d49559254791/sys/sys/elf32.h#L158
typedeffed to same thing: https://github.com/freebsd/freebsd-src/blob/b9a60d36ba043f313ab98b8dd058d49559254791/sys/sys/elf_common.h#L48
Solaris
https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html clearly states that it is 4-byte words for both 32-bit and 64-bit systems.
Illumos (opensolaris)
Elf32_Nhdr and Elf64_Nhdr has same definition: https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/sys/elf.h#L854
Also, elfnote writing has this comment: https://code.illumos.org/plugins/gitiles/illumos-gate/+/refs/heads/master/usr/src/uts/common/exec/elf/elf.c#1605
GHC
The best source explaining this mess I found in a comment of GHC's elf module: https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/SysTools/Elf.hs#L81
LLVM
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Object/ELFTypes.h#L596
everything as Elf_Word (=u32)
Commit message of this commit