summaryrefslogtreecommitdiffstats
path: root/libebl
Commit message (Collapse)AuthorAgeFilesLines
* Consolidate and add files to clean target variablesupstream/users/amerey/try-cleanMichael Pratt2024-11-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | To increase the consistency of how automatic clean targets run, define the variables together without +=, default to MOSTLYCLEANFILES when there is no need for different levels or add more clean levels to match other subdirectories, add more files that are built, remove duplication, and cleanup. Do the same for EXTRA_DIST where it is equally messy. * backends/Makefile.am: add more objects to clean, improve spacing. * debuginfod/Makefile.am: Likewise, and remove duplicates. * lib/Makefile.am: improve spacing. * libasm/Makefile.am: add more objects to clean, split similar to debuginfod. * libcpu/Makefile.am: use normal =, add more objects to clean. * libdw/Makefile.am: add more objects to clean, split similar to debuginfod. * libdwelf/Makefile.am: add more objects to clean, use lowest clean level. * libdwfl/Makefile.am: Likewise. * libebl/Makefile.am: add more objects to clean. * libelf/Makefile.am: add more objects to clean, split similar to debuginfod. * src/Makefile.am: consolidate including EXTRA_DIST, split clean levels, define with normal =, define with variables. * tests/Makefile.am: Likewise, but not including EXTRA_DIST. Signed-off-by: Michael Pratt <[email protected]>
* Remove usage of "unlocked" variant of stdio print functionsMichael Pratt2024-10-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These "unlocked" Linux Standard Base variants of standard functions are not available on some systems that are still capable of building Linux and ELFs. The difference is negligible for simple printing to stdout. POSIX also states for the similar putc_unlocked(): These functions can safely be used in a multi-threaded program if and only if they are called while the invoking thread owns the (FILE *) object, as is the case after a successful call to the flockfile() or ftrylockfile() functions. ... These unlocked versions can be safely used only within explicitly locked program regions, using exported locking primitives. and these precautions were never done. Use the standard forms of these print functions. There is inconsistent use of fputc_unlocked() with putc_unlocked(), so consistently use the safer fputc() instead. Signed-off-by: Michael Pratt <[email protected]>
* aarch64: Add NT_ARM_PAC_* regsetKuan-Ying Lee2024-08-301-0/+2
| | | | | | | Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64. Recognize and print the new core item. Signed-off-by: Kuan-Ying Lee <[email protected]>
* aarch64: add some new core note types nameKuan-Ying Lee2024-08-171-0/+3
| | | | | | Recognize names of some new core note types in ebl_core_note_type_name. Signed-off-by: Kuan-Ying Lee <[email protected]>
* aarch64: Add NT_ARM_TAGGED_ADDR_CTRL regsetKuan-Ying Lee2024-08-171-0/+1
| | | | | | | Add the NT_ARM_TAGGED_ADDR_CTRL regset for aarch64. Recognize and print this new core itme. Signed-off-by: Kuan-Ying Lee <[email protected]>
* readelf: add pretty printing for FDO Dlopen Metadata noteLuca Boccassi2024-05-312-2/+10
| | | | | | | | | | | | | The node ID and the string format are now fixed, even if the content of the string might change, it will still be a string. * libebl/eblobjnote.c (ebl_object_note): Handle both type being NT_FDO_PACKAGING_METADATA or NT_FDO_DLOPEN_METADATA when name is "FDO". * libebl/eblobjnotetypename.c (ebl_object_note_type_name): Handle "FDO" name and type NT_FDO_DLOPEN_METADATA. Signed-off-by: Luca Boccassi <[email protected]>
* Add support for HexagonMatheus Tavares Bernardino2024-04-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements initial support for the Hexagon architecture. The Hexagon ABI spec can be seen at https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf A hello_hexagon.ko test is also added. $ head tests/test-suite.log [...] # TOTAL: 275 # PASS: 269 # SKIP: 6 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 $ cat tests/run-strip-reloc-ko.sh.log [...] runtest hello_hexagon.ko PASS run-strip-reloc-ko.sh (exit status: 0) * backends/Makefile.am (modules): Add hexagon. (hexagon_SRCS): New var for hexagon_init.c and hexagon_symbol.c. (libebl_backends_a_SOURCES): Add hexagon_SRCS. * backends/hexagon_init.c: New file. * backends/hexagon_reloc.def: Likewise. * backends/hexagon_symbol.c: Likewise. * libebl/eblopenbackend.c (hexagon_init): Declare. (machines): Add hexagon. * libelf/elf-knowledge.h: Add hexagon e_flags values, section indices and and relocs. * src/elflint.c (valid_e_machine): Add EM_QDSP6. * tests/Makefile.am (EXTRA_DIST): Add hello_hexagon.ko.bz2. * tests/hello_hexagon.ko.bz2: New test file. * tests/run-strip-reloc-ko.sh: Add hello_hexagon.ko. Signed-off-by: Matheus Tavares Bernardino <[email protected]>
* Support Mips architectureYing Huang2024-03-291-0/+2
| | | | | | | | | | | | | | * backends/Makefile.am (modules): Add mips. (mips_SRCS): New var for mips_init.c mips_symbol.c. (libebl_backends_a_SOURCES): Add mips_SRCS. * backends/mips_init.c: New file. * backends/mips_reloc.def: Likewise. * backends/mips_symbol.c: Likewise. * libebl/eblopenbackend.c (mips_init): Declare. (machines): Add mips. * libelf/libelfP.h: Add ELF64_MIPS_R_TYPE{1,2,3} Signed-off-by: Ying Huang <[email protected]>
* libebl: ebl_object_note print 32bit annobin address ranges correctlyMark Wielaard2024-02-271-2/+2
| | | | | | | | | | | | | Annobin address ranges were always printed as if they were 64bit wide because addr_size was set to twice the size. This was done because the note description size should contain two addresses. Fix this by setting the address size to just one address and then check that descsz is twice that. * libebl/eblobjnote.c (ebl_object_note): Set addr_size to one ELF_T_ADDR. Check descsz equals two times addr_size. Signed-off-by: Mark Wielaard <[email protected]>
* libelf, readelf, elflint: Add RELR supportMark Wielaard2023-08-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle RELR as defined here: https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/YT2RrjpMAwAJ Introduce new ELF_T_RELR Elf_Type and handle it for SHT_RELR. Check various properties in elflint. Print RELR relocations in readelf. Just the entries with -U. Just the addresses with -N. And addresses plus symbol/offsets by default. Also add a test to check that gelf.h works with the system elf.h. * libebl/eblsectiontypename.c (ebl_section_type_name): Add RELR to knownstype. * libelf/elf32_updatenull.c (updatenull_wrlock): Handle sh_entsize for SHT_RELR. * libelf/gelf.h (GElf_Relr): New typedef for Elf64_Relr. * libelf/gelf_fsize.c (__libelf_type_sizes): Add ELF_T_RELR. * libelf/gelf_xlate.c (__elf_xfctstom): Likewise. * libelf/gelf_xlate.h: Add RELR as FUNDAMENTAL. * libelf/libelf.h (Elf_Type): Add ELF_T_RELR. Add RELR defines/typedefs if undefined in system elf.h. * libelf/libelfP.h: Define ELF32_FSZ_RELR and ELF64_FSZ_RELR. * src/elflint.c (check_reloc_shdr): Check she_entsize for ELF_T_RELR. (check_relr): New function. (check_dynamic): Handle DT_RELR. (special_sections): Add SHT_RELR. (check_sections): Call check_relr. * src/readelf.c (print_relocs): Also accept a Dwfl_Module. (handle_relocs_relr): New function. (print_dwarf_addr): Make static and declare early. (process_elf_file): Pass dwflmod to print_relocs. (handle_dynamic): Handle DT_RELRSZ and DTRELRENT. * system-elf-gelf-test.c: New test. * Makefile.am (TESTS): Add system-elf-gelf-test. (check_PROGRAMS): Likewise. (system_elf_gelf_test_CPPFLAGS): New variable. (system_elf_gelf_test_LDADD): Likewise. https://sourceware.org/bugzilla/show_bug.cgi?id=28495 Signed-off-by: Mark Wielaard <[email protected]>
* Add support for Synopsys ARCv2 processorsShahab Vahedi2022-12-222-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is no regression in tests for an x86_64 build, while the new hello_arc_hs4.ko is added as well. This is the only meaningful test that I could add at the moment, given the features supported by this port. $ cat tests/test-suite.log ========================================== elfutils 0.188: tests/test-suite.log ========================================== # TOTAL: 236 # PASS: 235 # SKIP: 1 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 .. contents:: :depth: 2 SKIP: run-lfs-symbols.sh ======================== LFS testing is irrelevant on this system SKIP run-lfs-symbols.sh (exit status: 77) $ cat tests/run-strip-reloc.sh.log runtest hello_i386.ko runtest hello_x86_64.ko runtest hello_ppc64.ko runtest hello_s390.ko runtest hello_aarch64.ko runtest hello_m68k.ko runtest hello_riscv64.ko runtest hello_csky.ko runtest hello_arc_hs4.ko <-- [ new ARC HS4 test ] runtest /home/shahab/pahole_pkg/elfutils-git/bld_arc/src/strip runtest /home/shahab/pahole_pkg/elfutils-git/bld_arc/src/strip.o runtest strip-uncompressed.o runtest strip-compressed.o runtest testfile-debug-rel-ppc64.o runtest testfile-debug-rel-ppc64-z.o runtest testfile-debug-rel-ppc64-g.o PASS run-strip-reloc.sh (exit status: 0) Signed-off-by: Shahab Vahedi <[email protected]>
* Add support for LoongArchHengqi Chen2022-12-192-0/+6
| | | | | | This implements initial support for the LoongArch architecture. Signed-off-by: Hengqi Chen <[email protected]>
* libebl: Don't #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.cYonggang Luo2022-10-273-2/+5
| | | | | | | It's not accessed symbols in dlfcn.h in eblclosebackend.c and eblopenbackend.c Signed-off-by: Yonggang Luo <[email protected]>
* Move the #include <libintl.h> into eu-config.hYonggang Luo2022-10-161-1/+0
| | | | | | | | | | So we do not need include in each file. And indeed the macro #define _(Str) dgettext ("elfutils", Str) access libintl function dgettext, so it's make more sense #include <libintl.h> in file eu-config.h Signed-off-by: Yonggang Luo <[email protected]>
* libelf: Sync elf.h from glibcAndreas Schwab2022-08-082-1/+6
| | | | | | | | | | Adds PT_RISCV_ATTRIBUTES, SHT_RISCV_ATTRIBUTES, PT_AARCH64_MEMTAG_MTE, RELR definitions, LoongArch relocations. dwelf_elf_e_machine_string was updated to handle EM_LOONGARCH, and ebl_dynamic_tag_name was updated to handle the new RELR dynamic tags. Signed-off-by: Andreas Schwab <[email protected]>
* Arm Ehdr flag printingUlrich Drepper2022-06-064-7/+21
| | | | | | | | | | | | | | | | | | Arm needs to decode flags and I modeled it after the binutils code. The same messages are printed. Given the requirement of the interface and the ABIs the current version of the callback function isn't sufficient unless one wants to create a stateful interface. The problem is that most flags need to be interpreted in the context of the ABI version. So I changed the API to also pass the original flag value. This shouldn't be a problem because there are no users yet. There is also a bug in ebl_machine_flag_name. When copying the string provided by the callback cp is moved past the NUL byte. It should move to the NUL byte. Otherwise one cannot anything but the first added flag description. Finally some cosmetic changes (space after each comma in the output). Signed-off-by: Mark Wielaard <[email protected]>
* libebl: recognize FDO Packaging Metadata ELF noteLuca Boccassi2022-03-243-0/+12
| | | | | | | | | | | | | As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/ this note will be used starting from Fedora 36. Allow readelf --notes to pretty print it: Note section [ 3] '.note.package' of 76 bytes at offset 0x2e8: Owner Data size Type FDO 57 FDO_PACKAGING_METADATA Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"} Signed-off-by: Luca Boccassi <[email protected]>
* Remove redundant casts of memory allocating functions returning void *Dmitry V. Levin2021-09-092-1/+5
| | | | | | | Return values of functions returning "void *", e.g. calloc, malloc, realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts. Signed-off-by: Dmitry V. Levin <[email protected]>
* Come up with startswith function.Martin Liska2021-05-123-4/+10
| | | | | | | New function in system.h that returns true if a string has a given prefix, false otherwise. Use it in place of strncmp. Signed-off-by: Martin Liška <[email protected]>
* Consistently define _(Str) using dgettext ("elfutils", Str)Dmitry V. Levin2020-12-162-5/+4
| | | | | | | | | | | | | | Move the definition of _(Str) macro to lib/eu-config.h which already provides a definition of N_(Str) macro. Since lib/eu-config.h is appended to config.h, it is included into every compilation unit and therefore both macros are now universally available. Remove all other definitions of N_(Str) and _(Str) macros from other files to avoid conflicts and redundancies. The next step is to replace all uses of gettext(Str) with _(Str). Signed-off-by: Dmitry V. Levin <[email protected]>
* libebl: consistently use _(Str) instead of gettext(Str)Dmitry V. Levin2020-12-1612-24/+38
| | | | | | | | | | | | libeblP.h defines _(Str) to dgettext ("elfutils", Str) instead of a simple gettext (Str) for a reason: the library might be indirectly used by clients that called bindtextdomain with a domain different from "elfutils". The change was made automatically using the following command: $ git grep -l '\<gettext *(' libebl |xargs sed -i 's/\<gettext *(/_(/g' Signed-off-by: Dmitry V. Levin <[email protected]>
* Fix spelling typos in NEWS, NOTES, TODO, and in comments of configure.acDmitry V. Levin2020-12-121-1/+1
| | | | | | | | | | | | | | | | | | | accidently -> accidentally approriate -> appropriate depencies -> dependencies endianess -> endianness funtions -> functions indeces -> indices indentified -> identified ist -> is mutliple -> multiple nessesary -> necessary optimze -> optimize severly -> severely suport -> support tranformation -> transformation Signed-off-by: Dmitry V. Levin <[email protected]>
* backends: Remove tilegx backend.Mark Wielaard2020-10-262-2/+6
| | | | | | | | Support for the Tilera TILE-Gx processor has been removed or deprecated in gcc and binutils already. There are no users and there is no way to test it. Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Remove unused ebl_syscall_abi.Mark Wielaard2020-10-266-70/+10
| | | | | | | | | GCC11 -Warray-parameter warned about ebl_syscall_abi being inconsistently declared (once with a pointer to int, once with an array of 6 int elements). Since ebl_syscall_abi isn't actually used and was only implemented for 3 backends without any tests just remove it. Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Handle aarch64 bti, pac bits in gnu property noteMark Wielaard2020-09-072-0/+72
| | | | | | | | | | | When building with gcc -mbranch-protection= we might get a gnu property note indicating BTI (Branch Target Identification) and/or PAC (Pointer Authentication Code) is being used. Add a small testcase to show eu-readelf -n now properly lists those bits in the gnu property note. Signed-off-by: Mark Wielaard <[email protected]>
* Only typedef Ebl once.Mark Wielaard2020-07-232-1/+7
| | | | | | | | | | | | | | | | Since commit 287a18452 libasm.h defines an opague Ebl handle. This is fine, except for (internal) code that also includes libebl.h. Since C11 having multiple typedefs for the same thing is fine, but we do build using GNU/C99. This also allows multiple same typedefs, except for (very) old GCCs. This only affects internal code, since libebl.h isn't a public header. For internal code, only add the typedef in libebl.h when libasm.h hasn't been included. Make sure all code that includes both headers includes libasm.h first. Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Remove Ebl struct size check and MODVERSION string.Mark Wielaard2020-06-103-19/+30
| | | | | | | | | | | | | | | | We used to do several sanity checks when the ebl backend libraries were loaded to make sure there was no version mismatch. When initializing the backend we passed the current Ebl struct size so the library could check it supported the given Ebl struct and we checked that the init method returned the correct build time module version string. Neither are necessary now that the backends are builtin. Remove both the struct size check and the MODVERSION string (which wasn't actually checked anymore). Make the init function return the given Ebl handle or NULL on error (no init function currently indicates any error). Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Sync elf.h from glibc.Mark Wielaard2020-06-042-4/+5
| | | | | | | There is now finally a PT_GNU_PROPERTY define. Also EM_ARC_COMPACT2 got renamed to EM_ARCV2. Signed-off-by: Mark Wielaard <[email protected]>
* libdw, readelf: Handle GCC LTO .gnu.debuglto_ prefix.Mark Wielaard2020-04-222-1/+8
| | | | | | | | | GCC puts (partial) DWARF debuginfo into sections prefixed with .gnu.debuglto_. Handle those sections as if they are normal .debug sections (which they are). This allows showing the DWARF that gcc puts into ET_REL files compiled with -flto. Signed-off-by: Mark Wielaard <[email protected]>
* readelf, elflint: Handle PT_GNU_PROPERTY.Mark Wielaard2020-02-182-0/+11
| | | | | | | | | binutils 2.32 ld emits a new PT_GNU_PROPERTY segment that overlaps with the PT_NOTE segment covering the .note.gnu.property section data. https://sourceware.org/bugzilla/show_bug.cgi?id=25511 Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Don't install libebl.a, libebl.h and remove backends from spec.Mark Wielaard2019-09-102-5/+7
| | | | | | | | All archive members from libebl.a are now in libdw.a. We don't generate separate backend shared libraries anymore. So remove them from the elfutils.spec file. Signed-off-by: Mark Wielaard <[email protected]>
* Don't use dlopen() for libebl modulesOmar Sandoval2019-08-296-177/+111
| | | | | | | | | | | | Currently, architecture-specific code for libebl exists in separate libebl_$ARCH.so libraries which libebl loads with dlopen() at runtime. This makes it impossible to have standalone, statically-linked binaries which use libdwfl if they depend on any architecture-specific functionality. Additionally, when these libraries cannot be found, the failure modes are non-obvious. So, let's get rid of libebl_$arch.so and move it all into libdw.so/libdw.a, which simplifies things considerably. Signed-off-by: Omar Sandoval <[email protected]>
* Add PIC and non-PIC variants of libcpu and libeblOmar Sandoval2019-08-282-2/+10
| | | | | | | | | Currently, libcpu and libebl are always compiled as PIC. An upcoming change will add the objects from libcpu.a and libebl.a to libdw.a, which should not be PIC unless configured that way. So, make libcpu.a and libebl.a non-PIC and add libcpu_pic.a and libebl_pic.a. Signed-off-by: Omar Sandoval <[email protected]>
* libebl: remove unnecessary variable in Makefile.amOmar Sandoval2019-08-282-20/+23
| | | | | | | gen_SOURCES is assigned to libebl_a_SOURCES and never used again. Get rid of it. Signed-off-by: Omar Sandoval <[email protected]>
* Add backend support for C-SKYMao Han2019-07-172-0/+5
| | | | | | | | | C-SKY V2 ABI manual: https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf C-SKY architecture user guide: https://github.com/c-sky/csky-doc/blob/master/CSKY%20Architecture%20user_guide.pdf Signed-off-by: Mao Han <[email protected]>
* libdwelf: Add dwelf_elf_e_machine_string and use it in readelf.Mark Wielaard2019-07-103-6/+6
| | | | | | | | | | | | | | | | To print eh human readable description of the ELF e_machine header field we used the ebl name. But this is not set for most EM constants. Introduce a new function dwelf_elf_e_machine_string that does work for all known EM values. Use that in eu-readelf to print a string representation of the e_machine value. Since this was the only usage of ebl->name, remove that from struct ebl. Also add a testcase that makes sure dwelf_elf_e_machine_string works for all EM values in the libelf/elf.h header so we will immediately notice when a new value appears. Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Try harder to find backend library in bin and lib origin paths.Mark Wielaard2019-05-302-47/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | eblopenbackend tries to find libraries based on the $ORIGIN/../$LIB/ path. But depending on whether the system is multilib or multiarch this doesn't always work. On multilib systems $LIB is always just one directory deep (it is either .../lib or .../lib64) but on multiarch systems it can be multiple directories deep (.../lib/x86_64-linux-gnu). This means that on multiarch systems $ORIGIN/../$LIB only works for binaries (where origin is .../bin/), but not for libraries. Most of the time it still works because of RPATH which is tried afterwards. But RPATH processing does not always work reliable. So try multiple paths first. The first time using the $ORIGIN as if it came from an executable (in bin/) and then using the $ORIGIN as if it came from an library (in lib[64]/ or lib/<arch>/). So first time using ../$LIB and second time just with the elfutils EBL_SUBDIR. The first is what we do now and always work on multilib systems. The second try works when loading relative to a library whether on a multilib or multiarch system. Then we use the same fallback (not using any path) we used already (to take advantage of any RPATH or LD_LIBRARY_PATH setting). https://sourceware.org/bugzilla/show_bug.cgi?id=24488 Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Check ebl is not NULL in ebl_symbol_[binding|type]_name.Mark Wielaard2019-04-283-0/+9
| | | | | | | For STB_GNU_UNIQUE and STT_GNU_IFUNC we need to check the elf of the given ebl. Make sure the ebl given isn't NULL. Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Check GNU property note data padding fits inside note.Mark Wielaard2019-01-302-8/+14
| | | | | | | | | The GNU property note data is padded. Make sure the extra padding still fits in the note description. https://sourceware.org/bugzilla/show_bug.cgi?id=24075 Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Check NT_PLATFORM core notes contain a zero terminated string.Mark Wielaard2019-01-163-21/+27
| | | | | | | | | | Most strings in core notes are fixed size. But NT_PLATFORM contains just a variable length string. Check that it is actually zero terminated before passing to readelf to print. https://sourceware.org/bugzilla/show_bug.cgi?id=24089 Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Check GNU property note pr_datasz fits inside note description.Mark Wielaard2019-01-162-0/+11
| | | | | | | | | Before printing the data values, make sure pr_datasz doesn't go beyond the end of the note description data. https://sourceware.org/bugzilla/show_bug.cgi?id=24075 Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Fix reading GNU_PROPERTY_STACK_SIZE reading from 32bit notes.Mark Wielaard2018-12-032-5/+20
| | | | | | | | | | | When reading a GNU_PROPERTY_STACK_SIZE we need to use the proper data type. GElf_Addr is 64bit always and when reading a 32bit size part of it would not be initialized. Use either Elf32_Addr or Elf64_Addr to read and print the data. Add 32bit and 64bit, little and big endian testcases. Signed-off-by: Mark Wielaard <[email protected]>
* libebl: Don't update w, t and len unnecessarily in ebl_object_note_type_name.Mark Wielaard2018-11-152-5/+8
| | | | | | Harmless, but useless. Signed-off-by: Mark Wielaard <[email protected]>
* Handle GNU Build Attribute ELF Notes.Mark Wielaard2018-11-134-4/+184
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GNU Build Attribute ELF Notes are generated by the GCC annobin plugin and described at https://fedoraproject.org/wiki/Toolchain/Watermark Unfortunately the constants aren't yet described in the standard glibc elf.h so they have been added to the elfutils specific elf-knowledge.h. The notes abuse the name owner field to encode some data not in the description. This makes it a bit hard to parse. We have to match the note owner name prefix (to "GA") to be sure the type is valid. We also cannot rely on the owner name being a valid C string since the attribute name and value can contain zero (terminators). So pass around namesz to the ebl note parsing functions. eu-elflint will recognize and eu-readelf -n will now show the notes: Note section [27] '.gnu.build.attributes' of 56080 bytes at offset 0x114564: Owner Data size Type GA 16 GNU Build Attribute OPEN Address Range: 0x2f30f - 0x2f30f VERSION: "3p8" GA 0 GNU Build Attribute OPEN TOOL: "gcc 8.2.1 20180801" GA 0 GNU Build Attribute OPEN "GOW": 45 GA 0 GNU Build Attribute OPEN STACK_PROT: 0 GA 0 GNU Build Attribute OPEN "stack_clash": TRUE GA 0 GNU Build Attribute OPEN "cf_protection": 0 GA 0 GNU Build Attribute OPEN "GLIBCXX_ASSERTIONS": TRUE GA 0 GNU Build Attribute OPEN "FORTIFY": 0 GA 0 GNU Build Attribute OPEN PIC: 3 GA 0 GNU Build Attribute OPEN SHORT_ENUM: FALSE GA 0 GNU Build Attribute OPEN ABI: c001100000012 GA 0 GNU Build Attribute OPEN "stack_realign": FALSE A new test was added to run-readelf -n for the existing annobin file. Signed-off-by: Mark Wielaard <[email protected]>
* Recognize NT_VERSION notes.Mark Wielaard2018-11-134-4/+27
| | | | | | | | NT_VERSION notes are emitted by the gas .version directive. They have an empty description and (ab)use the owner name to store the version data string. Signed-off-by: Mark Wielaard <[email protected]>
* Recognize and parse GNU Property notes.Mark Wielaard2018-10-293-1/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GNU Property notes are different from normal notes because they use variable alignment/padding of their fields. They are 8 byte aligned, but use 4 byte fields. The name is aligned at 4 bytes and padded so that, the desc is aligned at 8 bytes. The whole note is padded to 8 bytes again. For normal notes all fields are both 4 bytes wide and 4 bytes aligned. To recognize these new kind of ELF Notes a new Elf_Type is introduced, ELF_T_NHDR8. This type is used in the xlate functions to determine how to align and pad the various fields. Since the fields themselves can now have different alignments we will have to keep track of the current alignement and use either NOTE_ALIGN4 or NOTE_ALIGN8 to determine the padding. To set the correct Elf_Type on the Elf_Data we use either the section sh_addralign or the segment p_align values. Assuming 8 means the section or segment contains the new style notes, otherwise normal notes. When we cannot determine the "alignment" directly, like when parsing special kernel sys files, we check the name "GNU" and type "GNU_PROPERTY_TYPE_0" fields. ebl_object_note now parses the new NT_GNU_PROPERTY_TYPE_0 and can extract the GNU_PROPERTY_STACK_SIZE, GNU_PROPERTY_NO_COPY_ON_PROTECTED and GNU_PROPERTY_X86_FEATURE_1_AND types GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK. Tests are added for extracting the note from sections or segments as set by gcc -fcf-protection. Signed-off-by: Mark Wielaard <[email protected]>
* Handle ADD/SUB relocationsAndreas Schwab2018-10-135-7/+17
| | | | | | This adds support for ADD and SUB relocations as seen on RISC-V. Signed-off-by: Andreas Schwab <[email protected]>
* libebl: Use elf_getshdrstrndx in ebl_section_strip_p.Mark Wielaard2018-09-133-3/+12
| | | | | | | | | | The ebl_section_strip_p function used the Ehdr e_shstrndx field to get at the name of the (debug) sections. This is not correct if there are more than SHN_LORESERVE sections. Use elf_getshdrstrndx to get at the shstrtab section. And drop the Ehdr argument that isn't necessary anymore. Signed-off-by: Mark Wielaard <[email protected]>
* backends: Always use elf_getshdrstrndx in check_special_symbol.Mark Wielaard2018-09-135-6/+12
| | | | | | | | | | The check_special_symbol backend functions used the Ehdr e_shstrndx field to get at the name of sections. This is not correct if there are more than SHN_LORESERVE sections. Always use elf_getshdrstrndx to get the shstrtab section. And drop the Ehdr argument that isn't necessary anymore. Signed-off-by: Mark Wielaard <[email protected]>
* Consolidate error.h inclusion in system.hRoss Burton2018-07-052-1/+4
| | | | | | | | | error.h isn't standard and so isn't part of the musl C library. To easy future porting, consolidate the inclusion of error.h into system.h. https://sourceware.org/bugzilla/show_bug.cgi?id=21008 Signed-off-by: Ross Burton <[email protected]>