1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
Commit Graph

389 Commits

Author SHA1 Message Date
Georgii Rymar
11f7be54a0 [yaml2obj] - Stop using square brackets for unique suffixes.
For describing section/symbol names we can use unique suffixes,
e.g:

```
- Name: '.foo [1]`
- Name: '.foo [2]`
```

It can be a problem (see https://reviews.llvm.org/D79984#inline-734829),
because `[]` are sometimes used to describe a macros:

```
- Name: "[[a0]]"
```

Seems the better approach is to use something else, like "()".
This patch does it and refactors the code related.

Differential revision: https://reviews.llvm.org/D80123
2020-05-19 12:59:13 +03:00
Fangrui Song
4e41eb3f79 [llvm-objcopy][ELF] Allow --dump-section to dump an empty non-SHT_NOBITS section
This is the ELF part of D75949.

GNU objcopy from binutils 2.35 onwards will support an empty non-SHT_NOBITS section as
well
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=e052e2ba295a65b6ea80cbc3f90495beca299c42

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79339
2020-05-05 08:26:34 -07:00
Fangrui Song
288e72abc1 [llvm-objcopy][test] ELF/dump-section.test: change #CHECK to # CHECK
The latter is more common and thus the preferred way to use CHECK lines.
2020-05-05 08:26:34 -07:00
Alexander Shaposhnikov
c5ebacd65c [llvm-objcopy][MachO] Fix isExternalSymbol method
N_PEXT bit should not affect whether a symbol is considered to be external or not.
This also fixes the construction of the symbol table since it relies on the correct
ordering of symbols.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78888
2020-05-01 18:22:35 -07:00
Fangrui Song
4ae6ca1cf2 [llvm-objcopy] -O binary: skip empty sections
After SHF_ALLOC sections are ordered by LMA:

* If initial sections are empty, GNU objcopy skips their contents while we
  emit leading zeros. (binary-paddr.test %t4)
* If trailing sections are empty, GNU objcopy skips their contents while we
  emit trailing zeros. (binary-paddr.test %t5)

This patch matches GNU objcopy's behavior. Linkers don't keep p_memsz
PT_LOAD segments. Such empty sections would not have a containing
PT_LOAD and `Section::ParentSegment` might be null if linkers fail to
optimize the file offsets (lld D79254).

In particular, without D79254, the arm Linux kernel's multi_v5_defconfig
depends on this behavior: in `vmlinux`, an empty .text_itcm is mapped at
a very high address (0xfffe0000) but the kernel does not expect
`objcopy -O binary` to create a very large `arch/arm/boot/Image`
(0xfffe0000-0xc0000000 ~= 1GiB). See https://bugs.llvm.org/show_bug.cgi?id=45632

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79229
2020-05-01 14:25:37 -07:00
Martin Storsjö
579a3edad4 [llvm-objcopy] [COFF] Fix a misconception about debug directory payloads
The debug directory payload is not located directly after the
debug directory entry itself, but can essentially be located anywhere
in the binary (even outside of mapped sections, although we don't
handle that case).

Differential Revision: https://reviews.llvm.org/D78921
2020-04-29 20:35:36 +03:00
Alexander Shaposhnikov
6e8de6d572 [llvm-objcopy][MachO] Handle relocation entries where r_extern is zero
Fix handling of relocations with r_extern == 0.
If r_extern == 0 then r_symbolnum is an index of a section rather than a symbol index.

Patch by Seiya Nuta and Alexander Shaposhnikov.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78946
2020-04-27 17:59:07 -07:00
Alexander Shaposhnikov
8761b5042c [llvm-objcopy][MachO] Avoid accidental invalid relocations in tests
Until recently yaml2obj didn't properly support relocations for MachO.
This behavior resulted in binaries having invalid relocations.
In this diff we adjust the existing tests as follows:
for the tests which don't actually look at any relocations they are removed,
for the tests which essentially depend on relocations they are fixed.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78898
2020-04-27 15:33:17 -07:00
Fangrui Song
079c4bf20e [llvm-objcopy] Don't specialize the all zero p_paddr case
Spotted by https://reviews.llvm.org/D74755#1998673

> it looks like OrderedSegments in the function is only used to set the physical address to the virtual address when there are no physical addresses set amongst these sections.

I believe this behavior was copied from https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6ffd79000b45e77b3625143932ffbf781b6aecab (2008-05)
The commit was made for some corner cases of very old linkers.
This special rule does not seem useful and remove it can allow us to
delete a large chunk of code.

Reviewed By: jhenderson, jakehehrlich

Differential Revision: https://reviews.llvm.org/D78786
2020-04-27 11:20:41 -07:00
Alexander Shaposhnikov
e118dc8b0c [llvm-objcopy][MachO] Fix segment's vmsize
This diff fixes the calculation of the field vmsize
in LC_SEGMENT/LC_SEGMENT_64 load commands.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78799
2020-04-26 20:41:49 -07:00
Alexander Shaposhnikov
22888ebe65 [llvm-objcopy][MachO] Copy LC_LOAD_WEAK_DYLIB load commands
LC_LOAD_WEAK_DYLIB is analogous to LC_LOAD_DYLIB and doesn't require any special handling.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78602
2020-04-23 12:21:44 -07:00
Alexander Shaposhnikov
3158d1df4d [llvm-objcopy][MachO] Make --remove-section clean up dead symbols
Make --remove-section clean up dead symbols, return an Error if it can't be safely done.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78474
2020-04-22 14:26:42 -07:00
Georgii Rymar
67a986cd9a [yaml2obj] - Program headers: add an additional check for Offset
The `Offset` field is used to set the file offset of a program header.
In a normal object it should not be greater than the minimal offset
of sections included into segment.

This patch adds a check for that and adds tests.

Differential revision: https://reviews.llvm.org/D78304
2020-04-22 12:49:05 +03:00
Fangrui Song
1148aba0c6 Reland D76675 [llvm-objcopy] Match GNU behaviour regarding file symbols
Don't error on Config.KeepFileSymbols for COFF and Mach-O.

Original description:

GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: https://github.com/android/ndk/issues/1212

Differential Revision: https://reviews.llvm.org/D76675
2020-04-20 21:18:48 -07:00
Yi Kong
920851081d Revert "[llvm-objcopy] Match GNU behaviour regarding file symbols"
This reverts commit 7c65e88d0bc85ff2732a4e23c397ff842b97b828.

Broke non ELF targets.
2020-04-21 12:04:01 +08:00
Yi Kong
1e469f4962 [llvm-objcopy] Match GNU behaviour regarding file symbols
GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.

Bug: https://github.com/android/ndk/issues/1212

Differential Revision: https://reviews.llvm.org/D76675
2020-04-21 11:30:04 +08:00
Alexander Shaposhnikov
71a88d00fa [llvm-objcopy][MachO] Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands
Copy LC_ENCRYPT_INFO/LC_ENCRYPT_INFO_64 load commands.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D78339
2020-04-20 16:34:46 -07:00
Bill Wendling
568fc94f6d [Object] Use BFD name for little-endian PowerPC64
Summary:
Little-endian PowerPC object files should report "elf64-powerpcle" instead of
"elf64-powerpc".

Reviewers: jhenderson, MaskRay, espindola, alexshap, rupprecht, #powerpc

Reviewed By: MaskRay

Subscribers: wuzish, emaste, nemanjai, shchenz, steven.zhang, llvm-commits

Tags: #llvm, #powerpc

Differential Revision: https://reviews.llvm.org/D78344
2020-04-19 20:10:05 -07:00
Georgii Rymar
463ae4125d [tools][tests] - Use --check-prefixes instead of multiple --check-prefix. NFCI.
There is no need to use `--check-prefix` multiple times.
It helps to improve readability/test maintainability.
This patch does it for all tools at once.

Differential revision: https://reviews.llvm.org/D78217
2020-04-17 12:35:25 +03:00
Georgii Rymar
ced5ee12e6 [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.
Imagine we have the following invocation:

`FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=something`

When the check prefix does not exist it does not fail.
This patch fixes the issue.

Differential revision: https://reviews.llvm.org/D78024
2020-04-16 15:00:50 +03:00
Georgii Rymar
c549d7ded7 [LLVM/tools][test] - Remove/fix dead check prefixes.
We have a few unused/broken FileCheck prefixes in `llvm/test/tools`.
This patch fixes it.

Differential revision: https://reviews.llvm.org/D78110
2020-04-15 13:09:51 +03:00
Sid Manning
a2ae533cb7 Support bfdname "elf32-hexagon".
Add support and update testcases.

Differential Revision: https://reviews.llvm.org/D77579
2020-04-06 17:22:56 -05:00
James Henderson
ee219d49d3 Make test more robust
llvm-readobj prints the file path as part of the output, so
--implicit-check-not patterns can accidentally match it. This patch
makes the test more robust by preventing failures if "foo" is in
somebody's path.

Reviewed by: grimar

Differential Revision: https://reviews.llvm.org/D77546
2020-04-06 14:47:05 +01:00
Fangrui Song
b42400a541 [llvm-objcopy] Improve tool selection logic to recognize llvm-strip-$major as strip
Debian and some other distributions install llvm-strip as llvm-strip-$major (e.g. `/usr/bin/llvm-strip-9`)

D54193 made it work with llvm-strip-$major but did not add a test.
The behavior was regressed by D69146.

Fixes https://github.com/ClangBuiltLinux/linux/issues/940

Reviewed By: alexshap

Differential Revision: https://reviews.llvm.org/D76562
2020-03-23 13:49:26 -07:00
Vedant Kumar
af2c299da6 [test] Re-enable accidentally disabled X86 tests
A number of X86 tests were accidentally disabled in
https://reviews.llvm.org/D73568. This commit re-enables those tests.

```
$ for x86_test in $(gg 'REQUIRES: x86$' llvm/test | fst); do sed -i "" '/REQUIRES: x86/d' $x86_test; done
```

(Note that 'x86' is not an available feature, that's what caused the
tests to be disabled.)
2020-03-19 09:29:23 -07:00
Fangrui Song
bb43600d6c [Object] Change ELFObjectFile<ELFT>::getFileFormatName() to use BFD names
Follow-up for D74433

What the function returns are almost standard BFD names, except that "ELF" is
in uppercase instead of lowercase.

This patch changes "ELF" to "elf" and changes ARM/AArch64 to use their BFD names.
MIPS and PPC64 have endianness differences as well, but this patch does not intend to address them.

Advantages:

* llvm-objdump: the "file format " line matches GNU objdump on ARM/AArch64 objects
* "file format " line can be extracted and fed into llvm-objcopy -O literally.
  (https://github.com/ClangBuiltLinux/linux/issues/779 has such a use case)

Affected tools: llvm-readobj, llvm-objdump, llvm-dwarfdump, MCJIT (internal implementation detail, not exposed)

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D76046
2020-03-16 07:42:04 -07:00
Fangrui Song
1c1cc1c5ed [test] llvm/test/: change llvm-objdump single-dash long options to double-dash options
As announced here: http://lists.llvm.org/pipermail/llvm-dev/2019-April/131786.html

Grouped option syntax (POSIX Utility Conventions) does not play well with -long-option
A subsequent change will reject -long-option.
2020-03-15 17:46:23 -07:00
Georgii Rymar
89e0b77636 [yaml2obj] - Set a default value for PAddr property of a program header to a value of VAddr
`PAddr` corresponds to `p_paddr` of a program header, which is the segment's physical
address for systems in which physical addressing is relevant. `p_paddr` is often equal
to `p_vaddr`, which is the virtual address of a segment.

This patch changes the default for `PAddr` from 0 to a value of `VAddr`.

Differential revision: https://reviews.llvm.org/D76131
2020-03-14 17:44:57 +03:00
Jordan Rupprecht
654f0b7002 [llvm-readobj] Include section name of notes.
This changes the output of `llvm-readelf -n` from:

```
Displaying notes found at file offset 0x<...> with length 0x<...>:
```

to:

```
Displaying notes found in: .note.foo
```

And similarly, adds a `Name:` field to the `llvm-readobj -n` output for notes.

This change not only increases GNU compatibility, it also makes it much easier to read notes. Note that we still fall back to printing the file offset/length in cases where we don't have a section name, such as when printing notes in program headers or printing notes in a partially stripped file (GNU readelf does the same).

Fixes llvm.org/PR41339.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D75647
2020-03-05 09:53:14 -08:00
Fangrui Song
1e138660c8 [llvm-readelf] Make --all output order closer to GNU readelf
https://bugs.llvm.org/show_bug.cgi?id=43403

The new order makes it easy to compare the two tools' --all.

Reviewed By: grimar, rupprecht

Differential Revision: https://reviews.llvm.org/D75592
2020-03-04 12:22:12 -08:00
Alexander Shaposhnikov
f507c7164f [llvm-objcopy] Enable --discard-all for MachO
In this diff we enable the option --discard-all for MachO.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D75104
2020-02-26 12:51:15 -08:00
Fangrui Song
7263503150 [llvm-objcopy][test] Improve empty section tests
empty-sections.test: add two tests adapted from @jhenderson's https://reviews.llvm.org/D74755#1882221
strip-non-alloc.test: improve. D74755 will change the attribution of an empty section.

They mostly test the behavior of Object.cpp:sectionWithinSegment : how we attribute sections to segments.
`ParentSegment` can affect some subtle layout decisions.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D74879
2020-02-26 08:57:23 -08:00
Georgii Rymar
0ba63b8a56 [yaml2obj] - Automatically assign sh_addr for allocatable sections.
I've noticed that it is not convenient to create YAMLs from
binaries (using obj2yaml) that have to be test cases for obj2yaml
later (after applying yaml2obj).

The problem, for example is that obj2yaml emits "DynamicSymbols:"
key instead of .dynsym. It also does not create .dynstr.
And when a YAML document without explicitly defined .dynsym/.dynstr
is given to yaml2obj, we have issues:

1) These sections are placed after non-allocatable sections (I've fixed it in D74756).
2) They have VA == 0. User needs create descriptions for such sections explicitly manually
    to set a VA.

This patch addresses (2). I suggest to let yaml2obj assign virtual addresses by itself.
It makes an output binary to be much closer to "normal" ELF.
(It is still possible to use "Address: 0x0" for a section to get the original behavior
if it is needed)

Differential revision: https://reviews.llvm.org/D74764
2020-02-22 14:43:54 +03:00
Georgii Rymar
e522f14a05 [yaml2obj] - Change the order of implicitly created sections.
.dynsym and .dynstr are allocatable and therefore normally are placed
before non-allocatable .strtab, .shstrtab, .symtab sections.
But we are placing them after currently what creates a mix of
alloc/non-alloc sections and does not look normal.

Differential revision: https://reviews.llvm.org/D74756
2020-02-19 15:09:19 +03:00
Kadir Cetinkaya
b21a301b99 [llvm-objcopy] Fix pipeline syntax 2020-02-12 11:35:00 +01:00
Derek Schuff
0e37f48abc [llvm-objcopy][WebAssembly] Add dump/add/remove-section support
Add support for adding, removing, and dumping wasm sections to objcopy

Differential Revision: https://reviews.llvm.org/D70970
2020-02-11 15:17:18 -08:00
Fangrui Song
7e59988a3f [llvm-objcopy][test] Fix tests when path contains "bar"
Differential Revision: https://reviews.llvm.org/D72358
2020-01-30 17:56:12 -08:00
Derek Schuff
c56ad696b7 [llvm-objcopy] Initial support for wasm in llvm-objcopy
Currently only supports simple copying, other operations to follow.

Reviewers: sbc100, alexshap, jhenderson

Differential Revision: https://reviews.llvm.org/D70930

This is a reland of a928d127a with a one-line fix to ensure that
the wasm version number is written as little-endian (it's the only
field in all of the binary format that's not a single byte or an
LEB, but we may have to watch out more when we start handling the
linking section).
2020-01-29 17:32:02 -08:00
Derek Schuff
73b106d5b6 Revert "[llvm-objcopy] Initial support for wasm in llvm-objcopy"
This reverts commit a928d127a52a061733d2e42c4c9159a267f7dbd4.

It seems to cause issues with big-endian architectures.
2020-01-29 13:12:56 -08:00
Derek Schuff
e80bb1df0f [llvm-objcopy] Initial support for wasm in llvm-objcopy
Currently only supports simple copying, other operations to follow.

Reviewers: sbc100, alexshap, jhenderson

Differential Revision: https://reviews.llvm.org/D70930
2020-01-28 09:47:16 -08:00
Sergey Dmitriev
ce7722dd53 [llvm-objcopy][COFF] Add support for --set-section-flags
Reviewers: jhenderson, MaskRay, alexshap, rupprecht, mstorsjo

Reviewed By: jhenderson

Subscribers: abrachet, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73107
2020-01-24 07:12:55 -08:00
Fangrui Song
d68dfedd72 [test] Use yaml2obj -o %t instead of > %t
To improve consistency and avoid unneeded shell feature (output
redirection).

While here, make other changes to improve consistency

--docnum 1 => --docnum=1
-docnum=x => --docnum=x
2020-01-21 17:20:18 -08:00
Sergey Dmitriev
c4ed238e0b [llvm-objcopy][ELF] Allow setting SHF_EXCLUDE flag for ELF sections
Summary: This patch adds support for setting SHF_EXCLUDE flag for ELF sections.

Reviewers: jhenderson, grimar, MaskRay, mstorsjo, espindola, alexshap, rupprecht

Reviewed By: jhenderson, MaskRay

Subscribers: emaste, abrachet, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D72128
2020-01-20 18:56:45 -08:00
Fangrui Song
6817d16707 [llvm-readelf] Print EI_ABIVERSION as decimal instead of hexadecimal
This matches GNU readelf and llvm-readobj.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D72234
2020-01-06 09:25:45 -08:00
Georgii Rymar
f754b93e01 [llvm-readelf][llvm-readobj] - Reimplement the logic of section flags dumping.
Our logic that dumped the flags was buggy.

For LLVM style it dumped SHF_MASKPROC/SHF_MASKOS named constants, though
they are not flags, but masks.

For GNU style it was just very inconsistent with GNU which has logic
that is not straightforward. Imagine we have sh_flags == 0x90000000.
SHF_EXCLUDE ("E") has a value of 0x80000000 and SHF_MASKPROC is 0xf0000000.
GNU readelf will not print "E" or "Ep" in this case, but will print just
"p". It only will print "E" when no other processor flag is set.
I had to investigate the GNU source to find the algorithm and now our logic should
match it.

Differential revision: https://reviews.llvm.org/D71462
2019-12-18 10:44:40 +03:00
Fangrui Song
50bcd0d170 [llvm-objcopy][ELF] -O binary: use LMA instead of sh_offset to decide where to write section contents
.text sh_address=0x1000 sh_offset=0x1000
.data sh_address=0x3000 sh_offset=0x2000

In an objcopy -O binary output, the distance between two sections equal
their LMA differences (0x3000-0x1000), instead of their sh_offset
differences (0x2000-0x1000). This patch changes our behavior to match
GNU.

This rule gets more complex when the containing PT_LOAD has
p_vaddr!=p_paddr. GNU objcopy essentially computes
sh_offset-p_offset+p_paddr for each candidate section, and removes the
gap before the first address.

Added tests to binary-paddr.test to catch the compatibility problem.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D71035
2019-12-15 21:45:25 -08:00
Seiya Nuta
51ba164a74 [llvm-objcopy][MachO] Implement --add-section
Reviewers: alexshap, rupprecht, jhenderson

Reviewed By: alexshap, jhenderson

Subscribers: mgorny, jakehehrlich, abrachet, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66283
2019-12-16 14:07:29 +09:00
Fangrui Song
6e9a3eae4b [llvm-strip][MachO] Test llvm-strip --strip-debug
Reviewed By: smeenai

Differential Revision: https://reviews.llvm.org/D70995
2019-12-03 21:15:56 -08:00
Seiya Nuta
2619b4d02e [llvm-objcopy][MachO] Implement --dump-section
Reviewers: alexshap, rupprecht, jhenderson

Reviewed By: alexshap, rupprecht, jhenderson

Subscribers: MaskRay, jakehehrlich, abrachet, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66408
2019-11-25 12:30:37 +09:00
Fangrui Song
bea58c62af [llvm-objcopy][MachO] Implement --strip-debug
Reviewed By: alexshap

Differential Revision: https://reviews.llvm.org/D70476
2019-11-21 09:40:34 -08:00