From: Michael F. <mf...@mf...> - 2019-06-09 09:50:22
|
Hi, I'm looking at using elftoolchain instead of elfutils to satisfy the libelf dependency for objtool used in the linux build process. objtool is used to add ORC unwind sections to the objects. So far this is going well, but I have hit a few issues: 1. objtool defines its own elf_open function, used to open an ELF file by file path, which conflicts with the one used internally by elftoolchain. I don't think it should be an issue to rename the function in objtool, and I plan to submit a patch for this. Additionally, there was one usage of Elf_Scn by the struct tag instead of the typedef that needed fixing. 2. To check that the .o files were getting transformed in the same way as with elfutils, I compared the output of `readelf -a` on the results and noticed that the r_info field in the newly added .rela.orc_unwind sections differed between the two. It looks like this is because the elftoolchain ELF64_R_INFO macro shifts its first argument by 32, but objtool passes an unsigned int, so the value was getting lost. I resolved this with the diff below. 3. I also noticed that when elf_update recomputes the section layout, it leaves the section offset of SHT_NOBITS and SHT_NULL sections alone while the others are updated. elfutils sets the offset of the section based on the ending of the previous section. Does this offset have any meaning, or is it just arbitrary? Either way, maybe it makes sense to set it to the end of the previous section to avoid inheriting the value from the original section layout. 4. This is a bit unrelated to objtool, but I noticed that elfdefinitions.h contains several enums with values that are too big for int (specifically, EF_PPC_EMB, SHF_COMDEF, SHF_MIPS_STRING, SHF_EXCLUDE, SHF_MASKPROC, SHT_LOUSER, and SHT_HIUSER). The C standard says that all enumerator values must be representable as int, and have type int. Maybe it makes sense to use preprocessor defines for these instead? In addition to fixing ISO C conformance, this would also ensure that the enumerators have a consistent signedness (gcc will choose int for those less than 2^31, and unsigned for those that are greater or equal). Thanks for any help! diff --git a/common/elfdefinitions.h b/common/elfdefinitions.h index 0c207226..d00061ab 100644 --- a/common/elfdefinitions.h +++ b/common/elfdefinitions.h @@ -2806,7 +2806,7 @@ typedef struct { #define ELF64_R_SYM(I) ((I) >> 32) #define ELF64_R_TYPE(I) ((I) & 0xFFFFFFFFUL) -#define ELF64_R_INFO(S,T) (((S) << 32) + ((T) & 0xFFFFFFFFUL)) +#define ELF64_R_INFO(S,T) (((Elf64_Xword) (S) << 32) + ((T) & 0xFFFFFFFFUL)) /* * Symbol versioning structures. |