Commit Graph

80 Commits

Author SHA1 Message Date
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