Commit graph

255 commits

Author SHA1 Message Date
Ed Maste 3ca2845d13 libelftc: add elf{32,64}-tradlittlemips target emulation names
Sponsored by:	The FreeBSD Foundation
2016-12-10 01:40:10 +00:00
Conrad Meyer 7dc45d65e3 readelf(1) -S: Include zero index and match binutils' no-name
Include the SHN_UNDEF (zero) index special section in extended-attribute
ELF files, like GNU binutils' readelf.

Additionally, print "<no-name>" for sections without names, like GNU
binutils.

Reviewed by:	kaiw@
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8707
2016-12-07 18:33:40 +00:00
Conrad Meyer 714935be5a readelf(1): Add support for extended program header numbers
Add support for extended program header numbers to elftoolchain
'readelf -h'.

Reviewed by:	emaste
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8702
2016-12-05 03:11:52 +00:00
Ed Maste a402c1e54f c++filt: flush output after newline
Some tools spawn c++filt and pass it a single line at a time for
demangling. This is akin to r276689 for addr2line.

Sponsored by:	The FreeBSD Foundation
2016-11-09 15:04:29 +00:00
Ed Maste adb25d1e1a libelftc: add elf{32,64}-tradbigmips target emulation names
Reported by:	theraven
Sponsored by:	The FreeBSD Foundation
2016-11-07 22:41:52 +00:00
Ed Maste f8d647b44d strings: fix exit status if a file before the last one fails
Previously a command like "strings f1 f2 f3" reported the exit status
based only on processing the last file.

As with GNU strings, report an error exit status if an error was
encountered processing any of the files. While here simplify the
exit status handling to just success (0) / failure (1).

Reviewed by:	brooks
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D8334
2016-10-26 17:07:53 +00:00
Ed Maste d2972ce0cb elfcopy: select mode by the end of the program name
The mode of operation (elfcopy, mcs, or strip) is chosen based on the
program name.  Broaden this to allow a substring match at the end of the
name to allow prefixes - for example, bsdstrip or aarch64-freebsd-strip.

This improves use of these tools as drop-in replacements for GNU objcopy
and strip, which are often built with a limited set of supported targets
and installed with a target prefix for cross tools.

Reviewed by:	dim
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D1663
2016-10-22 23:49:06 +00:00
Mark Johnston feba6b4163 libdwarf: Add definitions for Apple's DWARF extension attributes.
Reviewed by:	emaste
MFC after:	1 week
2016-09-20 00:22:35 +00:00
Ed Maste d0bd2dad6f readelf: silence GCC 4.2.1 uninitialized variable warning
Sponsored by:	The FreeBSD Foundation
2016-08-31 21:04:58 +00:00
Ed Maste b6d812d2dd Update to ELF Tool Chain r3490
Improvements include:
 * readelf: report all relocation types in rel/rela for MIPS N64
 * readelf: add ELFOSABI_ARM_AEABI
 * elfdump: add ELFOSABI_ARM_AEABI and ELFOSABI_ARM
 * Add recent RISC-V relocations
 * elfcopy: use elftc_timestamp, to support SOURCE_DATE_EPOCH

Sponsored by:	The FreeBSD Foundation
2016-08-31 15:05:04 +00:00
Ed Maste d4a12237eb elfcopy: correct comment typo in r304151 2016-08-15 23:20:55 +00:00
Ed Maste e85c2b0b12 elfcopy: add elf64-littleaarch64 output target support
Sponsored by:	The FreeBSD Foundation
2016-08-15 14:28:08 +00:00
Ed Maste 07410fe461 elfcopy: silence GCC 5.3 unitialized variable warning
Although it's a false positive there is little cost to initializing it
always.

Submitted by:	adrian
2016-08-15 11:54:39 +00:00
Ed Maste 20136ffc7b readelf: report ARM program and section header types
Reviewed by:	andrew
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7390
2016-08-02 20:11:04 +00:00
Ed Maste 4e359ce1a0 libelftc: fix demangling of wchar_t
"wchar_t" is 7 characters long, not 6.

PR:		208661
Submitted by:	Daniel McRobb
Obtained from:	ELF Tool Chain r3480
MFC after:	3 days
2016-07-24 23:40:33 +00:00
Bryan Drewery 94bb24b387 Use the in-tree sys/elf_common.h to build libelftc.
This fixes build failures on older releases that lack various
definitions such as EM_AARCH64 (which was unfixed before this).

Revert all of the recent compatibility changes that worked around this
problem.

This uses the same method of using the in-tree header as lib/libelf,
lib/libdwarf and usr.bin/readelf.

Reviewed by:	emaste
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D6734
2016-06-05 23:05:14 +00:00
Ed Maste d38447b51d Update to ELF Tool Chain r3477
This fixes a EFI/PE header issue that prevented elfcopy-produced .efi
files from working with Secure Boot:

  Make sure section raw size is always padded to multiple of
  FileAlignment from the optional header, as requested by the PE
  specification. This change should reduce the diff between PE image
  generated by Binutils objcopy and elftoolchain elfcopy.

Submitted by:	kaiw
Reported by:	ambrisko
2016-05-25 20:56:30 +00:00
Ruslan Bukin ce35ddbc74 Add relocation support for RISC-V.
Reviewed by:	emaste
Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
Differential Revision:	https://reviews.freebsd.org/D6559
2016-05-25 11:58:55 +00:00
Ed Maste bcf9fc28f6 elftoolchain: backwards compatability for ELFOSABI_CLOUDABI definition
It is not provided by sys/elf_common.h on older releases or -current
before March 2015.

Reported by:	Jenkins
2016-05-21 15:38:40 +00:00
Ed Maste bdef86c693 elftoolchain: backwards compatability for EM_RISCV definition
It is not provided by sys/elf_common.h on older releases

Reported by:	Jenkins
2016-05-20 20:27:30 +00:00
Ed Maste d28b40c8d9 elftoolchain: backwards compatability for EM_IAMCU definition
It is not provided by sys/elf_common.h on older stable/10.
2016-05-20 18:54:42 +00:00
Ed Maste b6b6f9cc7c Update to ELF Tool Chain r3475
Improvements include:

 * Add support for reporting and handling a number of new constants in
   various tools, including:
    * CloudABI OSABI
    * DT_TLSDESC_*
    * i386, MIPS, SPARC and amd64 relocations

 * C++ demangler bug fixes

 * Man page updates

 * Improved input validation in several tools

This update also reduces diffs against upstream as a number of fixes
included in upstream were previously cherry-picked into FreeBSD.

Sponsored by:	The FreeBSD Foundation
2016-05-20 17:24:34 +00:00
Ed Maste e5c4075f6b elfcopy: map all !alnum characters to '_' in binary input symbol names
This matches bfd and gold.

Obtained from:	ELF Tool Chain r3445
Sponsored by:	The FreeBSD Foundation
2016-04-20 19:13:00 +00:00
Ed Maste d938d64e55 elfcopy: fix symbol table handling when sections come after symtab/strtab
Fix a symbol table handling bug in elfcopy: elfcopy puts .symtab,
  .strtab and .shstrtab sections in the end of the output object.  If
  the input objects have more sections after any of these 3 sections,
  the section table will be reordered, and in that case the section
  symbols should be regenerated for relocations.

  The bug is triggered since newer clang puts .strtab section in the
  beginning of the object produced.

   Ticket: #525

Reported by:	royger
Obtained from:	ELF Tool Chain r3443
2016-04-15 19:06:36 +00:00
Ed Maste 676e25ab0f elfcopy: overhaul of LMA handling
Merge ELF Tool Chain r3434:

    Previously, elfcopy defines:

    VMA:  section virtual address
    LMA:  PHDR(p_vaddr)

    While binutils(libbfd) defines:

    VMA:  section virtual address and PHDR(p_vaddr).
    LMA:  PHDR(p_paddr)

    For elfcopy, p_paddr is considered not meaningful and is always set
    to the same value as p_vaddr.

    elfcopy was implemented that way because I thought p_paddr is not
    used/meaningful according to the ELF ABI. However it turned out
    p_paddr is at least used in some ELF files, e.g. the FreeBSD kernel.

    This change made elfcopy treat p_paddr as LMA, same as libbfd.

    (However, some VMA/LMA related command line option still need tweaking
    to make them compatible with binutils objcopy. This will be improved
    later)

    Ticket: #524

And typo fixes in r3435 and r3436.

This fixes the Xen kernel build.

Submitted by:	kaiw
Tested by:	royger
2016-03-24 20:13:17 +00:00
Ed Maste a87342e849 libelf: correct byte count in cross-endian note translation
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-03-11 22:37:12 +00:00
Ed Maste 1e248b8346 libdwarf: fix SHT_REL relocation processing
Relocation of type SHT_REL must use the current value as addend.

PR:		204084
Obtained from:	NetBSD libdwarf_elf_init.c v1.4
2016-03-11 16:24:39 +00:00
Ed Maste f5e9c916af elfcopy: fail if debug link target is empty
An empty debug link target previously returned a confusing and incorrect
error like "objcopy: fread failed: No error: 0". Now, return an explicit
error.

GNU objcopy allows an empty file as the debug link target. However,
that case is nonsensical so diverging from GNU behaviour is fine.

Reviewed by:	bdrewery
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D5541
2016-03-04 18:28:19 +00:00
Ed Maste 3884d6f8bd Allow elfcopy to convert between two non-ELF formats
If the output object is not an ELF file, choose an arbitrary ELF format
for the intermediate file. srec, ihex and binary formats are independent
of class, endianness and machine type so these choices do not affect the
output.

ELF Tool Chain ticket #517

Reviewed by:	kai
Obtained from:	ELF Tool Chain r3411
2016-02-16 14:03:25 +00:00
Ed Maste 839529caa9 Update ELF Tool Chain to upstream rev 3400
Some notable improvements include:

readelf:
- Add AArch64 relocation definitions.
- Report value of unknown relocation types.

elfcopy:
- Consider symbols with STB_GNU_UNIQUE binding as global symbols.
- Fixed support for VMA adjustment for loadable sections found
  in relocatable objects.
- Handle nameless global symbols.
- Improve wildcard matching for !-prefixed symbols.
- Add PE/COFF support.

elfdump:
- Improve section type reporting.
- Add MIPS-specific section types.

This update also includes a significant number of bug fixes.

PR:		207091 [exp-run]
Sponsored by:	The FreeBSD Foundation
2016-02-12 20:54:02 +00:00
Ed Maste baed4bab22 readelf: decode AArch64 TLS descriptor relocations
From ELF for the ARM(R) 64-bit Architecture, table 4-19.

Obtained from:	ELF Tool Chain r3386
Sponsored by:	The FreeBSD Foundation
2016-02-05 20:57:21 +00:00
Ed Maste 03a5ea47c0 readelf: report value of unknown relocation types
Obtained from:	ELF Tool Chain r3387
Sponsored by:	The FreeBSD Foundation
2016-02-05 20:56:11 +00:00
Ed Maste 23541160bb readelf: avoid accidental fallthrough in RISC-V relocations
This would have printed an unknown RISC-V relocation type as a SPARC
relocation.

CID:		1331398
Obtained from:	ELF Tool Chain r3283
Sponsored by:	The FreeBSD Foundation
2016-02-05 20:54:51 +00:00
Ruslan Bukin 4f0a4502a1 Add config for RISC-V ISA.
Reviewed by:	emaste
Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
Differential Revision:	https://reviews.freebsd.org/D5046
2016-01-24 15:12:49 +00:00
Kai Wang 8f32e46db7 Fixed uninitialized variable warnings. 2015-12-13 08:27:14 +00:00
Ed Maste 95fd7f2615 Update to ELF Tool Chain r3272
Highlights (not already in the FreeBSD tree):
 - addr2line: Speed up and support searching inlined functions
 - addr2line: Support -i, -a, -p options
 - readelf: Add some ARM relocation types
 - readelf, libelf: Avoid reading beyond end of buffer/file

Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
2015-12-11 20:28:27 +00:00
Ed Maste 1ce1c68952 elfcopy: include extension but replace . when converting from binary
The change in r291958 was not consistent with GNU objcopy. The start,
end and size symbols created for ELF objects converted from binary need
to include the full filename including the extension, but with the
periods replaced with underscores.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D4474
2015-12-11 18:47:41 +00:00
Ed Maste fc7284da06 elfcopy: exclude extension when converting from binary
When converting from binary to ELF, elfcopy creates symbols
_binary_<filename>_start_, _binary_<filename>_end, and
_binary_<filename>_size. For compatibility with GNU objcopy (and to
produce sensible symbol names) the extension must be stripped off.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D4238
2015-12-07 20:21:12 +00:00
Ed Maste 895f86f15f readelf: add Xen ELF notes
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D4356
2015-12-03 12:21:18 +00:00
Ed Maste b54cfe0ae9 Add missing commas
Pointy hat to:	kan
Obtained from:	ELF Tool Chain r3253
2015-10-12 15:35:34 +00:00
Alexander Kabaev da1cc412c2 Add definitions for MIPS TLS relocations to elftoolchain.
This makes our readelf more useful when looking for TLS-related
issues.
2015-10-09 18:39:55 +00:00
Ed Maste 7a2e729ba2 addr2line: initialize die to NULL
GCC on MIPS produced a 'may be used uninitialized' warning after
r289071.

Reported by:	sbruno
Pointy hat to:	emaste
2015-10-09 18:26:24 +00:00
Ed Maste 656f49f8e2 Update to ELF Tool Chain r3250
Highlights (not already in the FreeBSD tree):
  - addr2line: Fixed multiple memory leaks related to DIE allocation
  - readelf: improve sh_link validation
  - various man page improvements

Sponsored by:	The FreeBSD Foundation
2015-10-09 17:46:05 +00:00
Ed Maste 453b09caf5 Rename ELFOSABI_SYSV to ELFOSABI_NONE to match current spec
Source: http://www.sco.com/developers/gabi/latest/ch4.eheader.html

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3731
2015-09-24 21:04:48 +00:00
Ed Maste 473c31f158 readelf: Correct typo HPUS -> HPUX
Submitted by:	kib
2015-09-24 18:53:20 +00:00
Ed Maste c9dbb1cc52 addr2line: skip CUs lacking debug info instead of bailing out
Some binaries (such as the FreeBSD kernel) contain a mixture of CUs
with and without debug information. Previously translate() exited upon
encountering a CU without debug information. Instead, just move on to
the next CU.

Reported by:	royger
Reviewed by:	royger
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3712
2015-09-22 16:51:40 +00:00
Ed Maste d8000daa92 Add ELF Tool Chain's brandelf(1) to contrib
Noticed by pfg after r286070 (ar and elfdump)
2015-07-31 12:37:40 +00:00
Ed Maste 3fe401a500 Add ELF Tool Chain's ar(1) and elfdump(1) to contrib
ELF Tool Chain built on FreeBSD's ar and elfdump, but has a number of
improvements and enhancements. Bring them into contrib in order to start
integrating into our build.
2015-07-30 12:41:54 +00:00
Ed Maste 71edbbfd5d readelf: avoid division by zero on section entry size
ELF Tool Chain tickets #439, #444, #445, #467
Reported by:	Alexander Cherepanov <cherepan@mccme.ru> (#467)
Reported by:	antiAgainst (others)

Reviewed by:	brooks
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D2338
2015-07-24 18:00:53 +00:00
Ed Maste 119b75925c Add RISC-V ELF machine type definition
EM_RISCV is now officially registered as e_machine 243.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-07-24 16:52:21 +00:00
Dimitry Andric 298022457a Fix endless recursion in dwarf_get_section_max_offsets(), found by clang
3.7.0.

Reviewed by:	emaste
2015-06-23 06:42:30 +00:00
Ed Maste 619ba3b416 elfcopy: Handle objects without a ".shstrtab" section string table
As of LLVM revision 238073, LLVM stores symbols and section names in
the same string table.  From the upstream commit mesage:

  With the scheme of naming sections like ".text.foo" where foo is a
  symbol, there is a big potential saving in using a single one.

This is a cherry-pick of ELF Tool Chain revision 3225.

Sponsored by:	The FreeBSD Foundation
2015-06-13 14:24:31 +00:00
Ed Maste 3ef90571c1 Update to ELF Tool Chain r3223
Highlights (upstream revisions):
 - Fix SHT_GROUP handling in elfcopy/strip (3206 3220 3221)
 - Misc elfcopy / strip bug fixes (3215 3216 3217)
 - Many C++ demangler improvements (3199 3200 3201 3202 3203 3204 3205
   3208 3210 3211 3212)
 - Improve GNU binutils compatibility in elfcopy / strip (3213 3214)
 - Add -g option to readelf(1): dump contents of section groups (3219)
 - Add EM_IAMCU 32-bit Intel MCU (3198)

Also add a compat #define for building with older FreeBSD ELF headers.
The GRP_COMDAT flag was added to elf_common.h in r283110, but it's not
available during the bootstrap build.  It is also convenient to be able
to build on older hosts.

Thanks to antoine@ for tracking down issues through multiple exp-runs
and to kaiw@ for fixing.

PR:		198611 (exp-run), 200350
Sponsored by:	The FreeBSD Foundation
2015-05-27 14:28:19 +00:00
Ed Maste b00fe64f4a Update to ELF Tool Chain r3197
Highlights:
 - Fix man page markup, whitespace, and typos
 - Fix sh_info of SHT_GROUP section to point to the correct string
 - Improve validation in readelf and elfcopy/strip
 - Handle DWARF 4's DW_AT_high_pc in addr2line

Sponsored by:	The FreeBSD Foundation
2015-05-14 19:48:15 +00:00
Ed Maste 67d97fe724 Update elftoolchain to upstream revision 3179
Some notable changes:
- libdwarf: Fixed DWARF4 line section
- elfcopy: Implement --localize-hidden
- nm: handle object name referenced by DW_AT_specification
- elfcopy: Add --strip-dwo and --extract-dwo options for split DWARF
- readelf: add remaining arm64 dynamic relocation names
- nm: Avoid integer overflow in value comparison

Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
2015-04-01 01:08:01 +00:00
Ed Maste 0b93a0b462 nm: avoid crash in print_lineno if func->name is NULL
This can occur when DW_AT_specification is used to refer to another DIE
that provides the actual DW_AT_name string. For example:

< 3><0x00000086> DW_TAG_subprogram
                   DW_AT_name              PrettyStackTraceEntry
...
< 1><0x00002cf4> DW_TAG_subprogram
                   DW_AT_specification     <0x00000086>

We will need to add support for DW_AT_specification, but in the interim
we should not segfault.

Obtained from:	Elftoolchain (r3170)
Sponsored by:	The FreeBSD Foundation
2015-02-25 21:43:09 +00:00
Ed Maste 71a0c925ce Update elftoolchain to upstream revision 3163
Most of our changes have now been committed upstream, so this change is
largely bookkeeping.

Sponsored by:	The FreeBSD Foundation
2015-02-17 15:19:58 +00:00
Ed Maste d133198b4b libdwarf: Handle .rel relocations
Some architectures use .rel relocations (for debug data), so they must
be handled.

This was discovered from ctfconvert on ARM object files.  The lack of
relocation handling caused all string lookups to return the string at
offset 0 in .debug_str, typically "FreeBSD clang version ..."

Reviewed by:	gnn, imp, rpaulo (earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D1819
2015-02-12 02:08:44 +00:00
Ed Maste f4bfb1fc59 libdwarf: Add symbol value when processing .rela relocations
Reviewed by:	kib, rpaulo
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1826
2015-02-11 19:53:44 +00:00
Ed Maste 84c37881c6 libdwarf: Add aarch64 relocation support
Reviewed by:	andrew, rpaulo
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D1817
2015-02-11 14:59:35 +00:00
Ed Maste 272a972b88 Preserve hard & symbolic links when modifying source file
Strip is often used to modify existing files, rather than creating new
files. If the existing file has hard links or is a symbolic link, act as
if editing the file in place and preserve the links.

Reported by:	luigi
Reviewed by:	imp, rpaulo
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D1682
2015-01-28 18:37:09 +00:00
Ed Maste 5773625048 redelf: Add missing R_X86_64_ relocation types
PR:		196918
Reviewed by:	dim
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D1570
2015-01-21 01:07:58 +00:00
Ed Maste 8ae6c16d82 Verify that section header offset is not past EOF
MFC After:	1 week
Sponsored by:	The FreeBSD Foundation
2015-01-16 15:16:19 +00:00
Ed Maste 2b39d4f68b elfcopy: Avoid divide-by-0 on section alignment 0
According to ELF ABI, alignment 0 and 1 has the same meaning: the
section has no alignment constraints.

PR:		196715
Sponsored by:	The FreeBSD Foundation
2015-01-14 14:49:58 +00:00
Ed Maste 93e0d5cabf libdwarf: add missing break
Reported by:	Coverity
CID:		1193315
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2015-01-13 15:18:54 +00:00
Ed Maste 9a1048f7e5 nm: Accept long option --extern-only for -g
Submitted by:	jkim
2015-01-08 14:35:16 +00:00
Ed Maste a737d64c08 libelf: Add arm64 config
Upstream elftoolchain ticket: #470
Submitted by:	Andrew Turner
Sponsored by:	The FreeBSD Foundation
2015-01-07 19:34:44 +00:00
Ed Maste 02b08c9092 readelf: Handle note types from different operating systems
Previously elftoolchain readelf(1) produced correct description text
only for Linux note types.

Upstream elftoolchain ticket #473

Differential Revision:	https://reviews.freebsd.org/D1428
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
2015-01-05 16:05:15 +00:00
Ed Maste a726543364 addr2line: fflush output after each address lookup
Certain tools spawn addr2line and pass addresses one at a time for
resolution.

PR:		195561
Reported by:	antoine
Sponsored by:	The FreeBSD Foundation
2015-01-05 04:56:38 +00:00
Ed Maste 34e3f14688 readelf: Correct rounding on note padding
In general 64-bit ELF notes use 4-byte padding, not 8, despite what is
claimed in various specs.

Upstream elftoolchain ticket 472
https://sourceforge.net/p/elftoolchain/tickets/472/

Sponsored by:	The FreeBSD Foundation
2015-01-02 20:49:43 +00:00
Ed Maste bc5438c566 libelf: Return an error instead of asserting on an invalid ar file
Upstream elftoolchain ticket 467
http://sourceforge.net/p/elftoolchain/tickets/467/

Reported by:	Alexander Cherepanov
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2015-01-02 02:47:47 +00:00
Ed Maste 3dc58d9cdb readelf: Add stdint.h for C99 fixed size types
Upstream elftoolchain brings in stdint.h via an ELF header that we
do not use in FreeBSD.

Sponsored by:	The FreeBSD Foundation
2014-12-31 19:21:53 +00:00
Ed Maste 47fc54d8b0 libelf: Rearrange size test to prevent integer overflow
Sponsored by:	The FreeBSD Foundation
2014-12-31 01:48:23 +00:00
Ed Maste 6db8a9f3a5 Check for multiplication integer overflow in CHECK_EHDR
The initial fix in r276374 is valid only for 64-bit objects. Revert it
and return an error in CHECK_EHDR if the multiplication would overflow.

The original buffer overflow issue was found with the security/afl
fuzzer and has upstream elftoolchain ticket 462. The 32-bit object issue
with r276374 found by antoine@ during an i386 exp-run.

Sponsored by:	The FreeBSD Foundation
2014-12-30 22:04:24 +00:00
Ed Maste 4a85c69160 Update elftoolchain to upstream rev 3136
This fixes two strip(1) issues found during ports exp-run and adds a
string hash implementation which significantly speeds up certain
operations on objects with large numbers of symbols.

This also improves libdwarf handling for stripped objects with
.eh_frame or .debug_frame (but not other debug) sections.

PR:		196107
Sponsored by:	The FreeBSD Foundation
2014-12-30 03:25:42 +00:00
Ed Maste 3a6f20c19a libelf: Do not read past end of buffer
Previously a corrupt ELF file could read beyond the end of e_rawfile.

Upstream elftoolchain ticket 462.  Found via the security/afl fuzzer.

Sponsored by:	The FreeBSD Foundation
2014-12-29 20:23:42 +00:00
Ed Maste 2013b96e58 Rename DT_FEATURE_1 to DT_FEATURE
Track r270303:

  This provides a minor cleanup in elfdump; there are otherwise no
  consumers in the tree.  Old SUN documentation can be found for either
  variant, but GNU binutils switched to DT_FEATURE around 2000.

Sponsored by:	The FreeBSD Foundation
2014-12-29 19:38:12 +00:00
Ed Maste 4a9f54ac69 Restore r276252 mdoc fix
It was accidentally reverted in the elftoolchain update (r276371).

Sponsored by:	The FreeBSD Foundation
2014-12-29 19:27:10 +00:00
Ed Maste b4e9f2392c Update elftoolchain to upstream rev 3130
This includes a number of libdwarf improvements (particularly DWARF4
related) and updates to elftoolchain tools such as strip(1). It also
includes a large number of miscellaneous fixes (memory leaks, sign and
cast warnings, integer overflow and underflow, etc.).

This is a merge of r276167,276170-276172 from the
projects/elftoolchain-update-r3130 branch.

Sponsored by:	The FreeBSD Foundation
2014-12-29 19:16:40 +00:00
Baptiste Daroussin e66fe60d56 mdoc fixes 2014-12-26 20:50:40 +00:00
Baptiste Daroussin df7f007fe8 mdoc fixes 2014-12-26 20:49:23 +00:00
Ed Maste cf781b2e16 Update elftoolchain to upstream rev 3130
This brings a number of fixes to elfcopy/strip and DWARF4 improvements.

Sponsored by:	The FreeBSD Foundation
2014-12-24 03:13:16 +00:00
Ed Maste b3f2680928 Add AArch64 machine time and relocations for readelf
Reviewed by:	andrew
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1333
2014-12-22 16:34:59 +00:00
Ed Maste 9ef62fdb87 Set up default shstrtab entries at shstrtab initialization
Instead of waiting until the addition of the first non-default entry.
This fixes a segfault when strip(1) is asked to remove every section from
an object file.

Upstream elftoolchain ticket 463

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1341
2014-12-22 16:31:09 +00:00
Ed Maste 17eee5222e Include section name in strip warning message 2014-12-18 19:09:59 +00:00
Ed Maste a356a1f51f Do not strip all when stripping an explicit symbol
When requested to strip specific symbols (-N flag) the default should be
to strip nothing (other than the requested symbols). This is consistent
with binutils strip(1).

PR:		196038
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1327
2014-12-17 14:46:21 +00:00
Ed Maste 2c23cb7c27 Copy elftoolchain readelf from vendor branch 2014-12-16 16:23:54 +00:00
Ed Maste 30568ad37e Correct elftoolchain strip(1) memory size calculation
Calculate the segment's memory size (p_memsz) using the virtual
addresses, not the file offsets. Otherwise padding preceeding SHT_NOBITS
sections may be excluded from the calculation, resulting in a segment
that is too small.

PR:		195653
Sponsored by:	The FreeBSD Foundation
2014-12-15 18:18:57 +00:00
Ed Maste ccbdcd03f2 libelf: Fix cross-endian ELF note file / memory conversion
The namesz and descsz variables need to be used in native endianness.
The sizes are in native order after swapping in the file to memory case,
and before swapping in the memory to file case.

This issue was identified for r273443, but the change was applied to the
wrong case. Revert r273443 to fix the to-memory case, and apply the
equivalent change to the to-file case.

Sponsored by:	DARPA, AFRL
Reviewed by:	adrian, brooks, marcel
Differential Revision: https://reviews.freebsd.org/D1257
2014-12-02 22:35:43 +00:00
Ed Maste 257d0dda42 Track libarchive API change 2014-12-01 16:10:44 +00:00
Ed Maste 310b1572ef Temporarily disable non-FreeBSD NT_ note types 2014-12-01 16:10:03 +00:00
Ed Maste 50f69bfbd6 Fix elftoolchain tools in-tree build
* make variables static
 * add header for uint*_t typedefs
2014-12-01 16:07:31 +00:00
Ed Maste a85fe12e36 Copy elftoolchain binutils replacements from vendor branch
Sponsored by:	The FreeBSD Foundation
2014-11-27 20:12:13 +00:00
Marcel Moolenaar c10185837c Fix the conversion macro for .note sections, broken in the case
the ELF file's byte order is not the native byte order.  The
bug is that the variables holding the name and description size
are used (natively) after having been byte-swapped.  The fix is
to calculate sz from them just prior to byte-swapping.

Approved by:	jkoshy@
Obtained from:	Juniper Networks, Inc.
2014-10-22 01:04:16 +00:00
Marcel Moolenaar 5da7d44acb GCC for PowerPC does not align .note sections to 4 bytes. When
running ctfmerge on its objects, libelf asserts as it expects
.note sections to be 4-byte aligned.  Change that expectation.

Approved by:	jkoshy@
Obtained from:	Juniper Networks, Inc.
2014-10-22 00:58:50 +00:00
Kai Wang ee3d625d72 Reapply r221569, r233401, r233524 and r255105: Add support for a few
ARM/MIPS ELF section types in _libelf_xlate_shtype().
2014-01-25 13:53:46 +00:00
Kai Wang 2496d1b162 Remove trailing whitespace. 2014-01-21 20:17:10 +00:00
Kai Wang bc5fce8d8f * Allow API dwarf_loclist_n() and dwarf_loclist() to be called with
attributes that have form DW_FORM_sec_offset.
* If the .debug_info section conforms to DWARF4, do not allow the value
  of attributes with form DW_FORM_data[48] to be used as section
  offset.
2014-01-19 13:42:49 +00:00
Kai Wang 255d921adc Add a sanity check: The provided offset for the desired location list
should not exceed the size of the .debug_loc section.
2014-01-19 13:38:40 +00:00
Kai Wang 9c016dc4b2 API dwarf_attrval_flag() should properly handle an attribute with
(DWARF4) form DW_FORM_flag_present which implicitly indicates the
presence of the attribute. Manual page is updated to reflect this
change.

Note that this was previously fixed in the old libdwarf.
2014-01-18 17:59:22 +00:00
Kai Wang 1201c6fd27 Fix typo: the public API dwarf_child() should return DW_DLV_NO_ENTRY
instead of DW_DLE_NO_ENTRY when a child DIE is not found.
2014-01-18 17:49:32 +00:00
Kai Wang 5371959e6f Fix a warning in libdwarf found by -Wmissing-variable-declarations. 2014-01-18 17:47:06 +00:00
Kai Wang 35b270102d Apply r241720 by ed:
Fix warnings found by -Wmising-variable-declarations.
2014-01-18 10:13:04 +00:00
Kai Wang 4e5c697507 Use FreeBSD's ELF headers instead of the elfdefinitions.h header which
comes with elftoolchain. This version of libelf doesn't need to be
portable; using FreeBSD's own ELF headers will avoid conflicts and
make integration easier.
2014-01-16 21:47:27 +00:00
Kai Wang 2de3b87a12 Copy libelf, libdwarf and common files from vendor/ to contrib/. 2014-01-15 22:30:48 +00:00