Thanks for your response. On 2019-06-09, Joseph Koshy <jko...@users.sourceforge.net> wrote: > On Sun, Jun 09, 2019 at 02:25:38AM -0700, Michael Forney wrote: > m.f> 3. I also noticed that when elf_update recomputes > m.f> the section layout, it leaves the section offset > m.f> of SHT_NOBITS and SHT_NULL sections alone while > m.f> the others are updated. elfutils sets the offset > m.f> of the section based on the ending of the previous > m.f> section. Does this offset have any meaning, or > m.f> is it just arbitrary? Either way, maybe it makes > m.f> sense to set it to the end of the previous section > m.f> to avoid inheriting the value from the original > m.f> section layout. > > Would you have a short example program that shows > the difference in behavior of elfutils' libelf and > elftoolchain's libelf? > > Per my understanding, for a section of type SHT_NULL, > the rest of the fields in the section header are > undefined. For a section of type SHT_NOBITS, > the offset and size fields are defined to be a > 'conceptual' offset and size of the section; these > values would be set by the application that adds a > SHT_NOBITS section to the object. > > When libelf is told to lay out an ELF object (i.e., > when the ELF_F_LAYOUT flag is not set on the Elf > descriptor), then it isn't clear what the fields of a > SHT_NOBITS section header would need to be set to.
I might be able to come up with an example later, but hopefully the attached shell session explains the difference I'm seeing. > m.f> 4. This is a bit unrelated to objtool, > m.f> but I noticed that elfdefinitions.h contains > m.f> several enums with values that are too big for > m.f> int (specifically, EF_PPC_EMB, SHF_COMDEF, > m.f> SHF_MIPS_STRING, SHF_EXCLUDE, SHF_MASKPROC, > m.f> SHT_LOUSER, and SHT_HIUSER). The C standard says > m.f> that all enumerator values must be representable as > m.f> int, and have type int. Maybe it makes sense to use > m.f> preprocessor defines for these instead? In addition > m.f> to fixing ISO C conformance, this would also ensure > m.f> that the enumerators have a consistent signedness > m.f> (gcc will choose int for those less than 2^31, > m.f> and unsigned for those that are greater or equal). > > I generally prefer using enumerations to preprocessor > symbols. Yes, generally I agree, but unfortunately the standard limits the values to the range of int, so they aren't suitable for some purposes. > As far as ISO C conformance goes, casting the literals > defining these symbols to 'int' might suffice, since > none of these values would need more than 32 bits > for their representation; I will take a look. Converting a value greater than INT_MAX to int is implementation defined, but perhaps it would work as intended for all implementations you care about. I also wonder if there are any cases where these large constants are shifted right. If they were cast to int, the sign extension could cause problems.
$ gcc -Wp,-MD,arch/x86/lib/.usercopy.o.d -nostdinc -isystem /lib/gcc/x86_64-linux-musl/8.2.0/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -fno-var-tracking-assignments -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fmacro-prefix-map=./= -Wno-packed-not-aligned -DKBUILD_BASENAME='usercopy' -DKBUILD_MODNAME='usercopy' -c -o arch/x86/lib/usercopy.o arch/x86/lib/usercopy.c $ readelf -S arch/x86/lib/usercopy.o | tee orig.txt There are 19 section headers, starting at offset 0x5f8: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000000000 00000040 000000000000007b 0000000000000000 AX 0 0 16 [ 2] .rela.text RELA 0000000000000000 000003f0 0000000000000060 0000000000000018 I 17 1 8 [ 3] .data PROGBITS 0000000000000000 000000bb 0000000000000000 0000000000000000 WA 0 0 1 [ 4] .bss NOBITS 0000000000000000 000000bb 0000000000000000 0000000000000000 WA 0 0 1 [ 5] ___ksymtab_gpl+co PROGBITS 0000000000000000 000000c0 0000000000000008 0000000000000000 A 0 0 8 [ 6] .rela___ksymtab_g RELA 0000000000000000 00000450 0000000000000030 0000000000000018 I 17 5 8 [ 7] .altinstructions PROGBITS 0000000000000000 000000c8 000000000000001a 0000000000000000 A 0 0 1 [ 8] .rela.altinstruct RELA 0000000000000000 00000480 0000000000000060 0000000000000018 I 17 7 8 [ 9] .altinstr_replace PROGBITS 0000000000000000 000000e2 000000000000000a 0000000000000000 AX 0 0 1 [10] .rela.altinstr_re RELA 0000000000000000 000004e0 0000000000000030 0000000000000018 I 17 9 8 [11] .discard.addressa PROGBITS 0000000000000000 000000f0 0000000000000008 0000000000000000 WA 0 0 8 [12] .rela.discard.add RELA 0000000000000000 00000510 0000000000000018 0000000000000018 I 17 11 8 [13] __ksymtab_strings PROGBITS 0000000000000000 000000f8 0000000000000013 0000000000000000 A 0 0 1 [14] .comment PROGBITS 0000000000000000 0000010b 0000000000000012 0000000000000001 MS 0 0 1 [15] .note.GNU-stack PROGBITS 0000000000000000 0000011d 0000000000000000 0000000000000000 0 0 1 [16] .shstrtab STRTAB 0000000000000000 00000528 00000000000000ce 0000000000000000 0 0 1 [17] .symtab SYMTAB 0000000000000000 00000120 00000000000001f8 0000000000000018 18 15 8 [18] .strtab STRTAB 0000000000000000 00000318 00000000000000d6 0000000000000000 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) $ cp arch/x86/lib/usercopy.o arch/x86/lib/usercopy.elfutils.o $ ./tools/objtool/objtool.elfutils orc generate --no-fp --retpoline arch/x86/lib/usercopy.elfutils.o $ readelf -S arch/x86/lib/usercopy.elfutils.o | tee elfutils.txt There are 22 section headers, starting at offset 0x700: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000000000 00000040 000000000000007b 0000000000000000 AX 0 0 16 [ 2] .rela.text RELA 0000000000000000 000000c0 0000000000000060 0000000000000018 I 17 1 8 [ 3] .data PROGBITS 0000000000000000 00000120 0000000000000000 0000000000000000 WA 0 0 1 [ 4] .bss NOBITS 0000000000000000 00000120 0000000000000000 0000000000000000 WA 0 0 1 [ 5] ___ksymtab_gpl+co PROGBITS 0000000000000000 00000120 0000000000000008 0000000000000000 A 0 0 8 [ 6] .rela___ksymtab_g RELA 0000000000000000 00000128 0000000000000030 0000000000000018 I 17 5 8 [ 7] .altinstructions PROGBITS 0000000000000000 00000158 000000000000001a 0000000000000000 A 0 0 1 [ 8] .rela.altinstruct RELA 0000000000000000 00000178 0000000000000060 0000000000000018 I 17 7 8 [ 9] .altinstr_replace PROGBITS 0000000000000000 000001d8 000000000000000a 0000000000000000 AX 0 0 1 [10] .rela.altinstr_re RELA 0000000000000000 000001e8 0000000000000030 0000000000000018 I 17 9 8 [11] .discard.addressa PROGBITS 0000000000000000 00000218 0000000000000008 0000000000000000 WA 0 0 8 [12] .rela.discard.add RELA 0000000000000000 00000220 0000000000000018 0000000000000018 I 17 11 8 [13] __ksymtab_strings PROGBITS 0000000000000000 00000238 0000000000000013 0000000000000000 A 0 0 1 [14] .comment PROGBITS 0000000000000000 0000024b 0000000000000012 0000000000000001 MS 0 0 1 [15] .note.GNU-stack PROGBITS 0000000000000000 0000025d 0000000000000000 0000000000000000 0 0 1 [16] .shstrtab STRTAB 0000000000000000 0000025d 00000000000000fd 0000000000000000 0 0 1 [17] .symtab SYMTAB 0000000000000000 00000360 00000000000001f8 0000000000000018 18 15 8 [18] .strtab STRTAB 0000000000000000 00000558 00000000000000d6 0000000000000000 0 0 1 [19] .orc_unwind_ip PROGBITS 0000000000000000 0000062e 0000000000000018 0000000000000004 A 0 0 1 [20] .rela.orc_unwind_ RELA 0000000000000000 00000648 0000000000000090 0000000000000018 I 17 19 8 [21] .orc_unwind PROGBITS 0000000000000000 000006d8 0000000000000024 0000000000000006 A 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), l (large), p (processor specific) $ ./tools/objtool/objtool.elftoolchain orc generate --no-fp --retpoline arch/x86/lib/usercopy.elftoolchain.o $ readelf -S arch/x86/lib/usercopy.elftoolchain.o > elftoolchain.txt $ diff -u elfutils.txt elftoolchain.txt --- elfutils.txt Sun Jun 9 19:54:52 2019 +++ elftoolchain.txt Sun Jun 9 19:54:44 2019 @@ -11,7 +11,7 @@ 0000000000000060 0000000000000018 I 17 1 8 [ 3] .data PROGBITS 0000000000000000 00000120 0000000000000000 0000000000000000 WA 0 0 1 - [ 4] .bss NOBITS 0000000000000000 00000120 + [ 4] .bss NOBITS 0000000000000000 000000bb 0000000000000000 0000000000000000 WA 0 0 1 [ 5] ___ksymtab_gpl+co PROGBITS 0000000000000000 00000120 0000000000000008 0000000000000000 A 0 0 8
_______________________________________________ Elftoolchain-developers mailing list Elftoolchain-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/elftoolchain-developers