Commit Graph

130 Commits

Author SHA1 Message Date
Ed Maste
aadb68849f elfcopy: copy raw (untranslated) contents to binary output
Previously elfcopy used elf_getdata to obtain data from ELF sections
being copied to binary output, but elf_getdata returns data that has
been translated - that is, data is in host byte order. When the host and
target differ in endianness (e.g., converting a big-endian MIPS ELF
object to binary on an x86 host) this resulted in byte-swapped data in
certain sections such as .dynamic.

Instead use elf_rawdata to keep data in the original, target endianness.

Reported by:	Hiroki Mori <yamori83@yahoo.co.jp>, Bill Yuan
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2018-01-02 14:07:55 +00:00
Ed Maste
7003cfb386 readelf: report byte size for DT_PREINIT_ARRAYSZ
Sponsored by:	The FreeBSD Foundation
2017-12-26 18:10:34 +00:00
John Baldwin
9fb35c8d7b Add missing newline after unknown MIPS-specific dynamic entries.
Reviewed by:	emaste
Sponsored by:	DARPA / AFRL
Differential Revision:	https://reviews.freebsd.org/D12384
2017-09-15 22:56:39 +00:00
John Baldwin
369bd05bc6 Recognize NT_PTLWPINFO and NT_ARM_VFP in FreeBSD ELF cores.
Reviewed by:	emaste
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D12371
2017-09-14 16:41:24 +00:00
Ruslan Bukin
ca20f8ec29 o Replace __riscv__ with __riscv
o Replace __riscv64 with (__riscv && __riscv_xlen == 64)

This is required to support new GCC 7.1 compiler.
This is compatible with current GCC 6.1 compiler.

RISC-V is extensible ISA and the idea here is to have built-in define
per each extension, so together with __riscv we will have some subset
of these as well (depending on -march string passed to compiler):

__riscv_compressed
__riscv_atomic
__riscv_mul
__riscv_div
__riscv_muldiv
__riscv_fdiv
__riscv_fsqrt
__riscv_float_abi_soft
__riscv_float_abi_single
__riscv_float_abi_double
__riscv_cmodel_medlow
__riscv_cmodel_medany
__riscv_cmodel_pic
__riscv_xlen

Reviewed by:	ngie
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D11901
2017-08-07 14:09:57 +00:00
Ed Maste
7582669623 readelf: correct printing of DT_FILTER and DT_AUXILIARY values
Previously these were shown only for MIPS objects.

Obtained from:	ELF Tool Chain r3564
MFC after:	1 week
MFC with:	r321045
Sponsored by:	The FreeBSD Foundation
2017-07-16 16:22:52 +00:00
Ed Maste
d62ecb4ecd readelf: fix printing of DT_FILTER and some other DT_* values
Some non-processor-specific DT_* values overlap the range DT_LOPROC to
DT_HIPROC.  Handle common ones first, then the processor-specific ones.

Obtained from:	ELF Tool Chain r3563
Sponsored by:	The FreeBSD Foundation
2017-07-16 12:30:39 +00:00
Ed Maste
18f4c9db68 Update to ELF Tool Chain snapshot at r3561
This update is primarily bug fixes in C++ symbol demangling, including:

- rvalue reference
- builtin type auto and decltype(auto)
- revamped support for function return types
- formatting fixes
- omit void when its the only param
- ref-qualifiers and others in function types
- type qualifiers in pointer-to-member function types
- incorrect handling regarding CV-qualifiers in function types
- ref-qualifier found in nested-name
- properly handle <name> ::= <substitute><template-args>
- make sure that nested function name is not a substitute candidate
- correctly handle expression in template args
- skip unknown substitution abbreviations

MFC after:	4 days
2017-06-25 22:39:28 +00:00
Ed Maste
9257ada0a4 nm: document 'r' symbol type
PR:		219245
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2017-05-22 01:10:12 +00:00
Ed Maste
42a4fda284 revert r308465: c++filt: flush output after newline
The ELF Tool Chain update to r3520 uses setvbuf to set line buffering.

Sponsored by:	The FreeBSD Foundation
2017-05-01 01:56:11 +00:00
Ed Maste
fa903e5725 elfcopy: allow empty symbol list files
Reported by:	bz
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D10441
2017-04-24 14:51:53 +00:00
Ed Maste
431bcfcdbd elfcopy: document --strip-symbols=filename in the man page
Reported by:	bz
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2017-04-20 13:57:53 +00:00
Ed Maste
e9f3f88adf readelf: dump MIPS abiflags section
This is not fully fleshed out but is sufficient to dump the
SHT_MIPS_ABIFLAGS used in FreeBSD.

Reviewed by:	imp
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D8241
2017-04-19 14:43:51 +00:00
Ed Maste
bee2765cc1 Update ELF Tool Chain to upstream r3520
Highlights of changes between r3490 and r3520:

- Improve C++ demangling
- Improve compatibility with Binutils tools wrt. error messages
- Handle additional types/sections/etc. in readelf and elfdump
- addr2line, cxxfilt: use setvbuf to set line buffering for filter use

PR:		218395
MFC after:	2 weeks
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
2017-04-17 23:56:48 +00:00
Ed Maste
f2911fa4a3 libelf: add an assert that msz is non-zero
Reported by:	Coverity
CID:		976023
2017-04-10 19:22:15 +00:00
Ed Maste
9bfb310cf3 elfcopy: remove temporary ELF file when converting from binary
Previously a command like

  objcopy --input-target binary --output-target elf64-x86-64-freebsd \
    binary_file object.o

would leave a temporary file behind.

ELF Tool Chain ticket #543

Reported by:	Roger Marquis
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2017-03-30 17:37:12 +00:00
Justin Hibbits
9569e13dce Add elf*-powerpc-freebsd targets to the elftoolchain target list
FreeBSD uses the full target triple when generating embedded rootfs images
(MFS_IMAGE= make option).  Without this change objcopy errors out with:

objcopy: elf64-poewrpc-freebsd: invalid target name

MFC after:	2 weeks
2017-02-08 03:21:29 +00:00
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