Commit Graph

17 Commits

Author SHA1 Message Date
Alexander Shaposhnikov 4d87344e8c [ObjCopy][NFC] Refactor handling of linkedit_data_command in MachOWriter 2022-04-10 02:09:11 +00:00
Alexander Shaposhnikov 68f87acd57 [ObjCopy][NFC] Add missing const in MachOLayoutBuilder.h 2022-04-10 01:29:24 +00:00
Alexander Shaposhnikov ddc0908949 [ObjCopy][NFC] Refactor handling of linkedit_data_command 2022-04-10 01:20:45 +00:00
Argyrios Kyrtzidis 330268ba34 [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes
Returning `std::array<uint8_t, N>` is better ergonomics for the hashing functions usage, instead of a `StringRef`:

* When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural
* Returning `std::array<uint8_t, N>` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef`

As part of this patch also:

* Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes.
* Make `MD5Result` inherit from `std::array<uint8_t, 16>` which improves & simplifies its API.

Differential Revision: https://reviews.llvm.org/D123100
2022-04-05 21:38:06 -07:00
Kazu Hirata c008e92b33 Apply clang-tidy fixes for modernize-use-equals-default in ELFObject.cpp (NFC) 2022-03-28 09:18:25 -07:00
Fangrui Song 30718f3aa6 [llvm-objcopy] --weaken-symbol/--weaken: weaken STB_GNU_UNIQUE symbols
STB_GNU_UNIQUE is like STB_GLOBAL with extra semantics:

* gold and ld.lld: changed to STB_GLOBAL if --no-gnu-unique is specified
* glibc: unique even with dlopen `RTLD_LOCAL`, implies DF_1_NODELETE

Therefore, I think it makes sense for --weaken-symbol/--weaken-symbols/--weaken
to change STB_GNU_UNIQUE symbols.

binutils 2.39 will have the same behavior: https://sourceware.org/bugzilla/show_bug.cgi?id=28926

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D120638
2022-03-16 09:48:19 -07:00
Fangrui Song cce3521020 [llvm-objcopy] Simplify CompressedSection creation. NFC
Remove Expected<CompressedSection> factory functions in favor of constructors
now that zlib::compress returns void (D121512).

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D121644
2022-03-14 23:15:15 -07:00
Fangrui Song 407c721ceb [Support] Change zlib::compress to return void
With a sufficiently large output buffer, the only failure is Z_MEM_ERROR.
Check it and call the noreturn report_bad_alloc_error if applicable.
resize_for_overwrite may call report_bad_alloc_error as well.

Now that there is no other error type, we can replace the return type with void
and simplify call sites.

Reviewed By: ikudrin

Differential Revision: https://reviews.llvm.org/D121512
2022-03-14 11:38:04 -07:00
Alexey Lapshin 2dc4a80ec0 [objcopy][NFC] Move NameOrPattern::create() into CommonConfig.h
While moving objcopy into separate library(D88827), NameOrPattern::create()
was mistakenly placed into ObjcopyOptions.cpp. This patch moves
the NameOrPattern::create() into CommonConfig.h. Additionally it adds
test for using NameOrPattern.

Differential Revision: https://reviews.llvm.org/D121005
2022-03-09 13:03:28 +03:00
Richard Howell 5917219438 [llvm] remove empty __LLVM segment in llvm-bitcode-strip
When running llvm-bitcode-strip we want to remove the __LLVM
segment as well as the __bundle section when there are no other
sections in the segment.

Differential Revision: https://reviews.llvm.org/D120927
2022-03-07 08:52:25 -08:00
Alexey Lapshin a6f3fedc3f [objcopy] Refactor CommonConfig to add posibility to specify added/updated sections as MemoryBuffer.
Current objcopy implementation has a possibility to add or update sections.
The incoming section is specified as a pair: section name and name of the file
containing section data. The interface does not allow to specify incoming
section as a memory buffer. This patch adds possibility to specify incoming
section as a memory buffer.

Differential Revision: https://reviews.llvm.org/D120486
2022-03-01 14:49:41 +03:00
esmeyi 61835d19a8 [llvm-objcopy] Initial XCOFF32 support.
Summary: This is an initial implementation of lvm-objcopy for XCOFF32.
Currently only supports simple copying, op-passthrough to follow.

Reviewed By: jhenderson, shchenz

Differential Revision: https://reviews.llvm.org/D97656
2022-02-28 04:59:46 -05:00
Alexey Lapshin 25d7b4fb44 [objcopy][NFC] Rename files to avoid clashing of archive members.
libtool uses file names to name members of an static library.
Files, located in different directories and having matching name,
would have the same name inside an archive. This is not a problem
for ld, but may be a problem for ar. This patch renames files
from ObjCopy library to avoid names clashing.

See https://reviews.llvm.org/D88827#3335814

Differential Revision: https://reviews.llvm.org/D120345
2022-02-23 13:05:39 +03:00
Sven van Haastregt 14f143c908 Fix llvm-objcopy shared lib build
Fix after ddf528b7a0 ("[llvm-objcopy][COFF] Fix section name
encoding", 2022-02-21) caused "undefined reference to
`llvm::COFF::encodeSectionName" failures.
2022-02-21 13:55:29 +00:00
Nicolas Miller ddf528b7a0 [llvm-objcopy][COFF] Fix section name encoding
The section name encoding for `llvm-objcopy` had two main issues, the
first is that the size used for the `snprintf` in the original code is
incorrect because `snprintf` adds a null byte, so this code was only
able to encode offsets of 6 digits - `/`, `\0` and 6 digits of the
offset - rather than the 7 digits it should support.

And the second part is that it didn't support the base64 encoding for
offsets larger than 7 digits.

This issue specifically showed up when using the `clang-offload-bundler`
with a binary containing a lot of symbols/sections, since it uses
`llvm-objcopy` to add the sections containing the offload code.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D118692
2022-02-21 13:50:57 +02:00
Alexey Lapshin a0c0db4627 [objcopy][NFC] Add rules to cmake to put files under specific folders.
This patch adds rules to cmake to put files under specific folders.

It allows to have files for different formats(which are located in different
subdirectories) be displayed in different subfolders of VS IDE solution.

Depends on D114429

Differential Revision: https://reviews.llvm.org/D114664
2022-02-18 13:17:29 +03:00
Alexey Lapshin f75da0c8e6 [llvm-objcopy][NFC] Move core implementation of llvm-objcopy into separate library.
This patch moves core implementation of llvm-objcopy into Object library
(http://lists.llvm.org/pipermail/llvm-dev/2020-September/145075.html).
The functionality for parsing input options is left inside tools/llvm-objcopy.
The interface of ObjCopy library:

ObjCopy/ELF/ELFObjcopy.h

```
Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
                           Buffer &Out);
Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In,
                                Buffer &Out);
Error executeObjcopyOnBinary(const CopyConfig &Config,
                             object::ELFObjectFileBase &In, Buffer &Out);

```
ObjCopy/COFF/COFFObjcopy.h

```
Error executeObjcopyOnBinary(const CopyConfig &Config,
                             object::COFFObjectFile &In, Buffer &Out);

```
ObjCopy/MachO/MachOObjcopy.h

```
Error executeObjcopyOnBinary(const CopyConfig &Config,
                             object::MachOObjectFile &In, Buffer &Out);

```
ObjCopy/wasm/WasmObjcopy.h

```
Error executeObjcopyOnBinary(const CopyConfig &Config,
                             object::WasmObjectFile &In, Buffer &Out);

```

Differential Revision: https://reviews.llvm.org/D88827
2022-02-17 13:11:42 +03:00