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

481 Commits

Author SHA1 Message Date
Jordan Rupprecht
97e61228e0 [NFC][llvm-objcopy] Fix redundant config checks.
The check for unsupported options checks some configs twice in a || expression. Fixes PR47107.
2020-08-11 10:37:19 -07:00
Sameer Arora
a27cdf02e5 Add symlinks for libtool and install_name_tool
Add symlinks for `llvm-libtool-darwin` and
`llvm-install-name-tool`.

Reviewed by jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D85054
2020-08-07 13:46:36 -07:00
Sameer Arora
9aaa6b386c [llvm-install-name-tool] Merge install-name options
This diff merges all options for llvm-install-name-tool under a single
function processLoadCommands. Also adds another test case for -add_rpath
option.

Test plan: make check-all

Reviewed by: jhenderson, alexshap, smeenai, Ktwu

Differential Revision: https://reviews.llvm.org/D82812
2020-07-06 20:32:32 -07:00
Eric Christopher
38ba3bf0b6 Temporarily Revert "[llvm-install-name-tool] Merge install-name options" as it breaks the objcopy build.
This reverts commit c143900a0851b2c7b7d52e4825c7f073b3474cf6.
2020-07-06 15:40:14 -07:00
Sameer Arora
c3954a3cf0 [llvm-install-name-tool] Merge install-name options
This diff merges all options for llvm-install-name-tool under a single
function processLoadCommands. Also adds another test case for -add_rpath
option.

Test plan: make check-all

Reviewed by: jhenderson, alexshap, smeenai, Ktwu

Differential Revision: https://reviews.llvm.org/D82812
2020-07-06 15:15:20 -07:00
Georgy Komarov
564d25cbd9 [llvm-objcopy] Fix crash when removing symbol table at same time as adding a symbol
This patch resolves crash that occurs when user wanted to remove all
symbols and add a brand new one using:

```
llvm-objcopy -R .symtab --add-symbol foo=1234 in.o out.o
```

Before these changes the symbol table internally being null when adding
new symbols. For now we will regenerate symtab in this case.

This fixes: https://bugs.llvm.org/show_bug.cgi?id=43930

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82935
2020-07-05 05:14:00 +03:00
Sameer Arora
d13ebe32f6 Fix typo and check commit access. 2020-07-02 14:49:47 -07:00
Sameer Arora
2f551c7741 [llvm-install-name-tool] Add -change option
Implement `-change` option for install-name-tool. The behavior exactly
matches that of cctools. Depends on D82410.

Reviewed By: jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D82613
2020-06-30 11:28:53 -07:00
Sameer Arora
c3265ed7a7 [llvm-install-name-tool] Add -id option
Implement `-id` option for install-name-tool. Differences from cctool's
behavior:
 - Does **NOT** throw an error if multiple -id options are specified.
    Instead, picks the last one.
 - Throws an error in case empty id is specified.

Reviewed By: jhenderson, smeenai

Differential Revision: https://reviews.llvm.org/D82410
2020-06-30 11:28:53 -07:00
Alexander Shaposhnikov
1130a0fbe6 [llvm-objcopy][MachO] Fix segment size alignment
This diff addresses the old TODO in MachOObjcopy.cpp and
correctly sets the page size used for alignment of segments.
In particular, now llvm-objcopy's output is consistent
with the input (the alignment of vmsize doesn't change).

Test plan:

1. make check-all
2. verify that a binary copied via llvm-objcopy now correctly works on iOS.

Differential revision: https://reviews.llvm.org/D82503
2020-06-29 23:55:21 -07:00
Bjorn Pettersson
79f2047cca [llvm-objcopy] Fix "unused-function" warning in NDEBUG builds
Fixup of commit b925ca37a8f28851 to allow building with
-Werror -Wunused-function.
2020-06-29 16:59:15 +02:00
Georgy Komarov
87e6a20dbb [llvm-objcopy] Emit error if removing symtab referenced by group section
SHT_GROUP sections contain a reference to a symbol indicating their
"signature" symbol. The symbol table containing this symbol is referred
to by the group section's sh_link field. If llvm-objcopy is instructed
to remove the symbol table, it will emit an error.

This fixes https://bugs.llvm.org/show_bug.cgi?id=46153.

Reviewed By: jhenderson, Higuoxing

Differential Revision: https://reviews.llvm.org/D82274
2020-06-29 10:42:03 +01:00
Alexander Shaposhnikov
1b6db69257 [llvm-install-name-tool] Add support for -rpath option
This diff implements -rpath option for llvm-install-name-tool
which replaces the rpath value in the specified Mach-O binary.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D82051
2020-06-26 17:23:03 -07:00
Sid Manning
9e71156d6d [Hexagon][llvm-objcopy] Add missing check for SHN_HEXAGON_SCOMMON_1
Differential Revision: https://reviews.llvm.org/D82484
2020-06-24 19:56:01 -05:00
Alexander Shaposhnikov
f1ab476248 [llvm-objcopy] Update help messages
This diff updates the help messages for llvm-objcopy, llvm-strip and
llvm-install-name-tool.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81907
2020-06-24 11:19:56 -07:00
Alexander Shaposhnikov
418d669e81 [llvm-install-name-tool] Implement delete_rpath option
This diff adds support for deleting an rpath from a Mach-O binary.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81527
2020-06-22 16:49:49 -07:00
Kirill Bobyrev
33517a77c3 NFC: Inline unused variable
The variable was not used anywhere except assert and causes build
warnings in the optimized builds.

Clanup after 913bc312b5516f0c7113fe14ea90097587ac5ca5
2020-06-16 08:29:52 +02:00
Alexander Shaposhnikov
3abfa57d76 [llvm-objcopy][MachO] Add support for LC_CODE_SIGNATURE
This diff adds support for copying binaries
containing a LC_CODE_SIGNATURE load command.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81768
2020-06-15 18:55:59 -07:00
Alexander Shaposhnikov
0f46c8ea11 [llvm-objcopy][MachO] Fix cmdsize of LC_RPATH
Fix the calculation of the field cmdsize (in the function buildRPathLoadCommand)
to account for the null byte terminator.

Patch by Sameer Arora!

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D81575
2020-06-11 19:55:04 -07:00
Reid Kleckner
6a61ba0a54 Re-land "Migrate the rest of COFFObjectFile to Error"
This reverts commit 101fbc01382edd89ea7b671104c68b30b2446cc0.

Remove leftover debugging attribute.

Update LLDB as well, which was missed before.
2020-06-11 14:46:16 -07:00
Nico Weber
e905d3fcf1 Revert "Migrate the rest of COFFObjectFile to Error"
This reverts commit b5289656b865d2a73cf90819e20a96fb8414ab0b.
__attribute__((optnone)) doesn't build with msvc, see
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/16326
2020-06-05 21:20:11 -04:00
Reid Kleckner
ce815b34d8 Migrate the rest of COFFObjectFile to Error 2020-06-05 16:29:05 -07:00
Sameer Arora
17ff76fd0f [llvm-objcopy] Reorder --dump-section for MachO
Reorder `DumpSection` under `handleArgs` in file `MachOObjcopy.cpp`. The
operation to dump a section is now performed before both add and remove
section operations for MachO file format.

Change for the ELF format at D81097. Together fixes
https://bugs.llvm.org/show_bug.cgi?id=44283

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D81123
2020-06-05 10:49:22 -07:00
Sameer Arora
8c5b6feb6f [llvm-objcopy] Reorder --dump-section before --remove-section for ELF
Reorder `DumpSection` under `handleArgs` in file `ELFObjcopy.cpp`.
`DumpSection` is placed before `replaceAndRemoveSections` and is
therefore now the first operation under `handleArgs`. Thus, it is now
performed before both `add` and `remove` section operations.

Change for the MachO format at D81123. Together fixes https://bugs.llvm.org/show_bug.cgi?id=44283.

Reviewed By: alexshap, jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D81097
2020-06-05 10:45:51 -07:00
Igor Kudrin
c2113b68ec [llvm-objcopy][ELF] Fix removing a group member.
When a group member is removed, the corresponding record in the
SHT_GROUP section has to be deleted.

This fixes PR46064.

Differential Revision: https://reviews.llvm.org/D80568
2020-05-29 20:24:53 +07:00
Igor Kudrin
786d96db56 [llvm-objcopy][ELF] Fix removing SHT_GROUP sections.
When a SHT_GROUP section is removed, but other sections of the group are
kept, the SHF_GROUP flag of these sections should be dropped, otherwise
the resulting ELF file will be malformed.

Differential Revision: https://reviews.llvm.org/D80511
2020-05-29 20:24:53 +07:00
Simon Pilgrim
5b2222b080 SymbolicFile.h - removed unused FileSystem.h include. NFC.
Exposes a number of implicit dependencies that needs fixing in source files and XCOFFObjectFile.h.
2020-05-28 15:26:31 +01:00
Alexander Shaposhnikov
372d313844 [llvm-objcopy][MachO] Add support for removing Swift symbols
cctools strip has the option "-T" which removes Swift symbols.
This diff implements this option in llvm-strip for MachO.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D80099
2020-05-26 16:49:56 -07:00
Alexander Shaposhnikov
742719477a [llvm-objcopy][MachO] Fix code formatting
Apply clang-format to MachOObjcopy.cpp. NFC.

Test plan: make check-all
2020-05-17 20:46:17 -07:00
Simon Pilgrim
9aba16961d Revert rGca18ce1a00cd8b7cb7ce0e130440f5ae1ffe86ee "GlobPattern.h - remove unnecessary BitVector.h/StringRef.h includes. NFC"
Causes lld build errors
2020-05-17 18:51:21 +01:00
Simon Pilgrim
dc62775ff9 GlobPattern.h - remove unnecessary BitVector.h/StringRef.h includes. NFC
Use forward declarations (BitVector already had one) and an headers to source file that were implicitly using them.
2020-05-17 18:29:41 +01:00
Reid Kleckner
24ad5a39c5 [COFF] Migrate COFFObjectFile to Expected<T>
I noticed that std::error_code() does one-time initialization. Avoid
that overhead with Expected<T> and llvm::Error. Also, it is consistent
with the virtual interface and ELF, and generally cleaner.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D79643
2020-05-08 14:01:39 -07: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
cf2a6f9195 [llvm-objcopy] Avoid invalid Sec.Offset after D79229
To avoid undefined behavior caught by -fsanitize=undefined on binary-paddr.test

  void SectionWriter::visit(const Section &Sec) {
    if (Sec.Type != SHT_NOBITS)
      // Sec.Contents is empty while Sec.Offset may be out of bound
      llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset);
  }
2020-05-03 21:57:51 -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
0216622484 [llvm-objcopy][MachO] Fix build
Some compilers are confused when the same name is used in different contexts.
Rename the field Section to unbreak the build.
(Caught by the buildbot http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/22374)
2020-04-27 18:20:01 -07: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
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
aede5a0e78 [llvm-objcopy][MachO] Add missing license header
Add missing license header to Object.cpp.
NFC.
2020-04-22 16:07:40 -07:00
Alexander Shaposhnikov
1827f4c151 [llvm-objcopy][MachO] Fix n_sect field
This tiny change is a follow-up to the previous commit f34fdbcf996a
where the update of n_sect was missing.

Test plan: make check-all
2020-04-22 15:44:03 -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
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
Lang Hames
4861433a3c [llvm-objcopy][MachO] Correctly identify object file endianness.
The header magic value is held in the native endianness, so the method used in
cc0ec3fdb9d. Use MachOReader / MachOWriter's existing endianness tests instead.
2020-04-16 21:54:01 -07:00