Commit Graph

113 Commits

Author SHA1 Message Date
Ed Maste
080b710889 strings: avoid unnecessary trip through handle_file for stdin
Sponsored by:	The FreeBSD Foundation
2017-01-25 20:59:06 +00:00
Ed Maste
c83bcfbd2e readelf: add S390 relocation types
From https://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries.html

Reviewed by:	bz
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D9149
2017-01-11 22:54:04 +00:00
Ed Maste
0fbbe5bf87 readelf: add more PPC64 relocation types found in LLVM
MFC after:	2 weeks
MFC with:	r311941
Sponsored by:	The FreeBSD Foundation
2017-01-11 21:28:22 +00:00
Ed Maste
dd9d62b416 readelf: add PPC64 relocation types
Reported by:	Mark Millard
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D9146
2017-01-11 21:18:14 +00:00
Mark Johnston
2ef476c9a2 Follow DW_AT_specification when looking up DW_AT_type attributes.
dwarf_attrval_*() will search the parent DIE referenced by a
DW_AT_abstract_origin attribute for the value of the DW_AT_type attribute.
Do the same thing for the DW_AT_specification attributes in variable
definitions emitted by GCC 6.2, and ensure that we return an error rather
than crashing if neither DW_AT_abstract_origin or DW_AT_specification is
found when looking for the value of the DW_AT_type attribute.

PR:		215350, 215395
Reviewed by:	emaste
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D8920
2016-12-28 21:54:33 +00:00
Ed Maste
d0aa56451e elfcopy: fix PE object section name corruption and crash
Fixed a bug that the PE object section names are generated incorrectly
using the section name table found in the original input ELF object
instead of the intermediate ELF object.

Ticket:		#541

Do not try to copy section content from a NULL d_buf when creating
uninitialized data COFF section for PE object.

Ticket:		#540

Obtained from:	ELF Tool Chain r3507, r3508
MFC after:	1 week
2016-12-27 17:31:07 +00:00
Conrad Meyer
93326017f6 gelf_getphdr: Allow extended indices
Needed for 'readelf -l' of extended phnum files.  (Parity with GNU
binutils.)

Reviewed by:	no one, unfortunately
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8703
2016-12-16 01:42:51 +00:00
Conrad Meyer
1d1bfbbb38 libelf: Fix extended numbering detection
Extended numbering is used for any of these fields overflowing.

Reviewed by:	emaste@
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8701
2016-12-16 01:39:06 +00:00
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