Commit Graph

2229 Commits

Author SHA1 Message Date
Mark Wielaard 1e52d4ce3a s390: elflint should check if _GLOBAL_OFFSET_TABLE_ points to .got.
The _GLOBAL_OFFSET_TABLE_ symbol might point to the DT_PLTGOT,
which is in the .got section, even if the symbol itself is
associated with the .got.plt section.

See https://sourceware.org/ml/binutils/2018-07/msg00200.html

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-02-15 14:39:57 +01:00
Mark Wielaard 89f5c7b57e Prepare for 0.176
Set version to 0.176.
Update NEWS and elfutils.spec.in.
Update GPG-KEY.
Regenerate po/*.po files.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-02-14 14:40:21 +01:00
Mark Wielaard e32380ecef libelf: Make sure ar_size is terminated when reading ar long names.
The ar_size is given as a fixed size decimal string, right padded with
spaces.  Make sure we read it properly even if there is no terminating
space. Also sanity check len early if we can.

https://sourceware.org/bugzilla/show_bug.cgi?id=24085

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-02-14 11:47:59 +01:00
Mark Wielaard e8f8dc465a libdw: Check there is enough space for CU 64bit length, version and type.
We only checked we could read the initial length and after knowing the
version and type whether the unit header was the right size. Also check
there are at least enough bytes to read the 64bit length, version and
unit type bytes.

https://sourceware.org/bugzilla/show_bug.cgi?id=24140

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-02-01 14:06:18 +01:00
Mark Wielaard cad9595592 readelf: Check there is enough data to read DWARF line opcodes arguments.
When reading the debug_line opcode arguments we have to make sure there
is enough data to read the arguments (if there are any(.

The similar code in dwarf_getsrclines already had these checks.

https://sourceware.org/bugzilla/show_bug.cgi?id=24116

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-02-01 09:08:14 +01:00
Mark Wielaard b63007ed58 configure: Add new --enable-install-elfh option.
We explicitly test (with system-elf-libelf) that our include headers
work with the system elf.h header. But it might be helpful to install
the elf.h file for a private install. Our elf.h header really is just
a copy of the latest glibc elf.h. But it might be newer and include
more constants than the system installed elf.h.

Add a new configure option --enable-install-elfh to install elf.h.
But warn when it is enabled for the default /usr or /usr/local prefix
because it might clash with the glibc/system elf.h header in that case.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-31 23:51:17 +01:00
Mark Wielaard fe7d3f3635 tests: Remove assert (errno == 0) from tests.
When a function fails it might set errno. But it isn't a guarantee
that if a function succeeds that it sets errno to zero.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-31 23:18:25 +01:00
Yonghong Song cfaf954701 tests: parse inode in /proc/pid/maps/correctly in run-backtrace-data.sh
The backtrace-data.c parsed the inode in /proc/pid/maps with
format "%*x".
This caused failure if inode is big. For example,
  7f269223d000-7f269226b000 r-xp 00000000 00:50 10224326387095067468       /home/...

The error likes below:
  -bash-4.4$ cat run-backtrace-data.sh.log
  backtrace-data: /home/engshare/elfutils/0.174/src/elfutils-0.174/tests/backtrace-data.c:110:
    maps_lookup: Assertion `errno == 0' failed.
  /home/engshare/elfutils/0.174/src/elfutils-0.174/tests/test-subr.sh: line 84:
    3123578 Aborted                 (core dumped)
    LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" $VALGRIND_CMD "$@"
  data: no main
  -bash-4.4$
The reason is errno is ERANGE.

Fix the test with inode format string "%*u" as inode here is presented
as decimal numbers.

Suggested-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
2019-01-31 22:18:10 +01:00
Mark Wielaard cd7ded3df4 libebl: Check GNU property note data padding fits inside note.
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 <mark@klomp.org>
2019-01-30 00:04:11 +01:00
Yonghong Song 14ec482463 libdwfl: parse inode in /proc/pid/maps correctly
The inode number in /proc/pid/maps is displayed as "unsigned long"
type.

In one of our x64 system, we have inode number exceeding valid "long"
type range, which caused the following test failure:
   FAIL: dwfl-bug-fd-leak
   FAIL: run-backtrace-dwarf.sh
   FAIL: vdsosyms

The offending map entry:
  7f269246b000-7f269246c000 rw-p 0002e000 00:50 10224326387095067468 /home/...

This patch changed sscanf inode number type from PRIi64 to PRIu64
and fixed the problem.

Signed-off-by: Yonghong Song <yhs@fb.com>
2019-01-29 21:07:51 +01:00
Ulf Hermann b548f4fe92 tests: Use separate files for strip outputs
This way we can verify that strip actually created all of them.
Also, check that strip, unstrip, elflint actually succeed in
run-strip-test-many.sh. This exposed the fact that the generated
testfile in run-strip-test-many.sh is considered as illformed by
strip -g.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
2019-01-24 16:06:29 +01:00
Mark Wielaard 4540ea98ce strip: Fix check test for SHN_XINDEX symbol.
The check for whether a symbol used the extended section table was
wrong causing the run-strip-test-many.sh testcase to declare the
testfile was an illformed file.

Fixing this exposed a strict elfutils check for the '.shstrtab'
section having this exact name and a SHT_STRTAB type. This might
be a little too strict, but easily worked around by changing the
name of the "old" shstrtab section in the addsections program.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-24 16:06:29 +01:00
Mark Wielaard a17c2c0917 readelf: Don't go past end of line data reading unknown opcode parameters.
https://sourceware.org/bugzilla/show_bug.cgi?id=24116

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-22 18:12:38 +01:00
Mark Wielaard 2562759d6f libdw: Check terminating NUL byte in dwarf_getsrclines for dir/file table.
For DWARF version < 5 the .debug_line directory and file tables consist
of a terminating NUL byte after all strings. The code used to just skip
this without checking it actually existed. This could case a spurious
read past the end of data.

Fix the same issue in readelf.

https://sourceware.org/bugzilla/show_bug.cgi?id=24102

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-22 18:12:38 +01:00
Mark Wielaard da5c5336a1 libdwfl: Sanity check partial core file dyn data read.
When reading the dyn data from the core file check if we got everything,
or just part of the data.

https://sourceware.org/bugzilla/show_bug.cgi?id=24103

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-22 17:42:42 +01:00
Mark Wielaard de01cc6f94 libebl: Check NT_PLATFORM core notes contain a zero terminated string.
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 <mark@klomp.org>
2019-01-16 15:41:31 +01:00
Mark Wielaard e65d91d21c libelf: Correct overflow check in note_xlate.
We want to make sure the note_len doesn't overflow and becomes shorter
than the note header. But the namesz and descsz checks got the note header
size wrong). Replace the wrong constant (8) with a sizeof cvt_Nhdr (12).

https://sourceware.org/bugzilla/show_bug.cgi?id=24084

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-01-16 12:25:57 +01:00
Mark Wielaard 012018907c libebl: Check GNU property note pr_datasz fits inside note description.
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 <mark@klomp.org>
2019-01-16 12:08:16 +01:00
Ulf Hermann 9af7aaf9d9 Skip run-readelf-compressed.sh test if built without bzip2
Obviously, we cannot read the compressed ELF file if no bzip2 support is
present.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
2019-01-13 23:18:06 +01:00
Jim Wilson dcd3704ee5 RISC-V: Add untested 32-bit core file support.
Adds 32-bit support exactly the same way that the sparc backend handles
32- and 64-bit core file support.  The 64-bit core file support was tested
and still works same as before.

Signed-off-by: Jim Wilson <jimw@sifive.com>
2019-01-13 11:08:42 +01:00
Jim Wilson 4f4b90c609 RISC-V: Add initial return value location support.
Started with the aarch64 support and modified it for RISC-V.  The
flattened structure support hasn't been written yet, but the rest of
it should be correct for the LP64D ABI.  We have potentially 6 different
ABIs to support, so this requires checking elf header flags in riscv_init
when setting the hook.

Signed-off-by: Jim Wilson <jimw@sifive.com>
2019-01-10 13:25:33 +01:00
Jim Wilson 1dabad36ee RISC-V: Improve riscv64 core file support.
This fixes two problems.  The offset for x1 is changed from 1 to 8 because
this is a byte offset not a register skip count.  Support for reading the
PC value is added.  This requires changing the testsuite to match the new
readelf output for coredumps.

Signed-off-by: Jim Wilson <jimw@sifive.com>
2019-01-08 23:52:11 +01:00
Mark Wielaard e8b9832af1 libebl: Fix reading GNU_PROPERTY_STACK_SIZE reading from 32bit notes.
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 <mark@klomp.org>
2018-12-03 00:03:39 +01:00
Mark Wielaard 63160fceaa tests: Improve backtrace-data SKIP message.
The backtrace-data testcase is x86_64 linux only because it uses its
own set_initial_registers and scans its own /proc/pid/maps file.
The SKIP message it gave on other platforms was misleading. It said
"Unwinding not supported for this architecture". Change it to
"x86_64 linux only test" to be less confusing.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-28 13:58:31 +01:00
Mark Wielaard 90727b9e8c libdwfl: Fix relocation overlap sanity check.
We would not relocate when the relocation section data or the target
section date would overlap with one of the ELF headers. This is only
really necessary if the data comes directly from the mmapped file.
Otherwise there is no real overlap and the relocations can be safely
applied.

One particular thing we got wrong with the original sanity check was
when the relocation data or target data section was compressed. In
that case it could happen we overestimated the size (because the Shdr
would have been updated to show the uncompressed data size). But
uncompressed data is always malloced and so cannot overlap with the
mmapped Elf header structures.

When building with CFLAGS="-g -Og" this showed up as a failure in
run-strip-reloc.sh for strip-compressed.o. Where the .debug_loc
section decompressed would "overlap" with the shdrs at the end of
the file and so wouldn't get relocations applied.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-23 21:10:27 +01:00
Mark Wielaard ffbe89d879 libdw: Enable building with -Og.
When building with -Og gcc is unable to see that __libdw_dieabbrev ()
will initialize what the second argument points to when no error occurs
as called by dwarf_child and dwarf_getattrs. Causing an possibly
uninitialized error. Just initialize readp/die_addr to NULL, which is
the value we would return if an error occurs anyway.

https://sourceware.org/bugzilla/show_bug.cgi?id=23914

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-23 21:06:30 +01:00
Mark Wielaard 628b4a93c6 tests: Call test_cleanup in backtrace-subr.sh check_unsupported.
We want to make sure all (temporary) test files are cleaned up even when
we exit 77 to skip the testcase.

https://sourceware.org/bugzilla/show_bug.cgi?id=23901

Tested-by: Kurt Roeckx <kurt@roeckx.be>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-21 20:07:14 +01:00
Mark Wielaard 5f9fab9efb libelf: Get alignment correct when calling conversion functions.
When writing out data that needs to be converted we have to make sure
the conversion function is called on correctly aligned buffers. When
using mmap this might mean we have to convert into a temporarily buffer
if the user wants to write out the section at a location that is not
correctly aligned for the section type.

Older gas would generate misaligned ELF notes for the .version
directive. When copying over such notes using mmap from files with
a different endianness using mmap we would get the alignment of the
conversion destination wrong.

The new testcase would fail with configure --enable-sanitize-undefined
on little endian systems. The GCC undefinited sanitizer caught a similar
issue with testfile1 on big endian systems.

gelf_xlate.h:47:1: runtime error: member access within misaligned address
0x7f8145d770d5 for type 'struct Elf32_Nhdr', which requires 4 byte alignment

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-21 12:30:12 +01:00
Mark Wielaard f5810ec76c Add -Wtrampolines to CFLAGS.
elfutils uses nested functions a lot. This is fine unless one takes the
address of such a nested function. When taking the address of a nested
function a trampoline is generated that on some systems require the stack
to be executable. That is bad. We never want to generate such trampolines.
Add -Wtrampolines to CLAGS to make sure we don't.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-21 12:30:12 +01:00
Mark Wielaard c93f060df3 config/upload-release.sh: Need to make before make dist.
Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-16 12:52:00 +01:00
Mark Wielaard 4ea9a2db16 Update upload-release.sh script and po files.
Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-16 12:44:53 +01:00
Mark Wielaard a01938d584 libelf: Mark both fsize and msize with const attribute.
GCC9 -Wmissing-attributes pointed out that although we alias the fsize
and msize functions only fsize was marked as const. Fix by also marking
the msize definition as const.

https://sourceware.org/bugzilla/show_bug.cgi?id=23884

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-16 09:27:00 +01:00
Mark Wielaard c338a05416 libebl: Don't update w, t and len unnecessarily in ebl_object_note_type_name.
Harmless, but useless.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-15 15:53:41 +01:00
Mark Wielaard 422b549007 Prepare for 0.175
Set version to 0.175
Update NEWS and elfutils.spec.in.
Regenerate po/*.po files.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-14 13:14:00 +01:00
Mark Wielaard 22ec8efc1d elflint: Allow PT_GNU_EH_FRAME segment to match SHT_X86_64_UNWIND section.
The gold linker might generate an .eh_frame_hdr with a SHT_X86_64_UNWIND
type instead of a SHT_PROGBITS type.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-13 22:16:26 +01:00
Mark Wielaard cf10453f82 libelf: Correctly setup alignment of SHF_COMPRESSED section data.
We didn't set the alignment of SHF_COMPRESSED sections correctly.
Those sections start with an Elf(32|64)_Chdr. Make sure sh_addralign
is setup to be able to read such a struct directly. Likewise don't
trust the alignment set on any SHF_COMPRESSED section, but always
make the (raw) compressed data aligned correctly for the reading the
Elf(32|64)_Chdr directly.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-13 21:30:17 +01:00
Mark Wielaard d3e6266754 strip: Also handle gnu compressed debug sections with --reloc-debug-sections
Check whether a section was gnu compressed and decompress it first
before trying to resolve relocations. Recompress it afterwards.

This found a bug in elf_compress_gnu which would use the "raw" file
contents even if the user had just created the section (copying over
the section from the original input file).

Add compressed ET_REL tests to run-strip-reloc.sh testcase.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-13 16:53:40 +01:00
Mark Wielaard 72e30c2e0c Handle GNU Build Attribute ELF Notes.
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 <mark@klomp.org>
2018-11-13 13:46:40 +01:00
Mark Wielaard 7a3f6fe60b Recognize NT_VERSION notes.
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 <mark@klomp.org>
2018-11-13 13:40:00 +01:00
Mark Wielaard cff53f1784 libcpu: Recognize bpf jump variants BPF_JLT, BPF_JLE, BPF_JSLT and BPF_JSLE
Linux kernel 4.13 introduced 4 more jump class variants.

  commit 92b31a9af73b3a3fc801899335d6c47966351830
  Author: Daniel Borkmann <daniel@iogearbox.net>
  Date:   Thu Aug 10 01:39:55 2017 +0200

    bpf: add BPF_J{LT,LE,SLT,SLE} instructions

For conditional jumping on unsigned and signed < and <= between a register
and another register or immediate.

Add these new constants to bpf.h, recognize them in bpf_disasm and update
the testfile-bpf-dis1.expect file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-09 18:26:38 +01:00
Mark Wielaard ecbe3120cd libdwelf: New function dwelf_elf_begin.
This introduces a new function dwelf_elf_begin which creates a (read-only)
ELF handle from a possibly compressed file handle or a file that start
with a linux kernel header. This can be used in eu-readelf to (re)open a
(pure) ELF.

eu-readelf uses libdwfl to relocate addresses in the original file in
case it is ET_REL. But to show the "raw" data it might need to (re)open
the file. Which could fail if the file was compressed. And produced an
obscure error message: "cannot create EBL handle".

This rewrites __libdw_open_file a little so that the given file handle
will never be closed (whether on success or failure) and introduces a
new internal function __libdw_open_elf that dwelf_elf_begin wraps.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-09 18:11:48 +01:00
Mark Wielaard 4b0342b85b backends: Add x86_64 section_type_name for SHT_X86_64_UNWIND.
Makes sure that eu-readelf and eu-elflint recognize and show the
x86_64 specific section type correctly.

Signed-off-by: Mark Wielaard <mark@klomp.org>
Tested-by: Milian Wolff <milian.wolff@kdab.com>
2018-11-09 17:53:18 +01:00
Milian Wolff 825e48c4e9 Also find CFI in sections of type SHT_X86_64_UNWIND
On my system with g++ (GCC) 8.2.1 20180831 with GNU gold (GNU Binutils
2.31.1) 1.16, the .eh_frame section does not have type PROGBITS
but rather is using X86_64_UNWIND nowadays:

```
$ echo "int main(){ return 0; }" > test.c
$ gcc test.c
$ readelf --sections a.out | grep .eh_frame
  [14] .eh_frame         X86_64_UNWIND    0000000000000670  00000670
  [15] .eh_frame_hdr     X86_64_UNWIND    0000000000000724  00000724
```

Without this patch, libdw refuses to use the available unwind
information, leading to broken backtraces while unwinding. With the
patch applied, unwinding works once more in such situations.

Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
Tested-by: Milian Wolff <milian.wolff@kdab.com>
2018-11-09 17:51:30 +01:00
Mark Wielaard 4789e0fb92 libelf: Explicitly update section data after (de)compression.
We need to explictly trigger a section data reload after updating the
ELF section rawdata to make sure it gets written out to disk on an
elf_update. Doing this showed one bug/inefficiently when the underlying
file has a different endianness. In that case for debug sections we
would convert by allocating a new buffer and just copying over the
raw data into a new buffer. This is not really necessary and would
hide any relocations done on the rawdata by libdwfl.

Added a couple of new ppc64 big endian testfiles that show the issue.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-09 17:34:30 +01:00
Mark Wielaard 1628254ba2 strip: Add --reloc-debug-sections-only option.
This option does the same thing as --reloc-debug-sections without doing
any other strip operation. This is useful when you want to remove the
debug section relocations in a separate ET_REL debug file that was created
without --reloc-debug-sections, or for a file (like the linux debug vmlinux)
that you don't want to strip, but for which the debug section relocations
can be resolved already.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-06 12:07:48 +01:00
Mark Wielaard f2d59180b9 strip: Extract code to update shdrstrndx into new common function.
Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-06 12:07:48 +01:00
Mark Wielaard f6ae0ab935 strip: Split out debug section relocation into separate helper functions.
Extract a couple of helper functions out of handle_elf (secndx_name,
get_xndxdata and remove_debug_relocations) so they can be reused more
easily in the future.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-06 12:07:48 +01:00
Mark Wielaard b15ee95bce strip: Always copy over any phdrs if there are any.
Ignore the type of ELF file, just copy over any phdrs if the original
file contained any. Also refuse to move around any allocated sections
based on whether there are any phdrs instead of on ELF file type.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-06 12:07:48 +01:00
Mark Wielaard e574889d92 unstrip: Add ELF_CHECK to make sure gelf_getehdr () doesn't return NULL.
Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-11-02 23:17:05 +01:00
Mark Wielaard 5199e15870 Recognize and parse GNU Property notes.
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 <mark@klomp.org>
2018-10-29 00:57:57 +01:00