aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-25[llvm-objcopy] Remove unused includes (NFC) (#141389)Kazu Hirata1-14/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-03-07[llvm-strip] Let llvm-strip continue on encountering an error (#129531)Tejas Vipin1-2/+4
This change means that llvm-strip no longer exits immediately upon encountering an error when modifying a file and will instead continue modifying the other inputs. Fixes #129412
2025-01-23Reapply "[llvm-objcopy][ELF] Add an option to remove notes (#118739)"Igor Kudrin1-0/+2
This fixes "unused-local-typedef" warnings in 9324e6a7a5. This adds an option `--remove-note=[name/]type` to selectively delete notes in ELF files, where `type` is the numeric value of the note type and `name` is the name of the originator. The name can be omitted, in which case all notes of the specified type will be removed. For now, only `SHT_NOTE` sections that are not associated with segments are handled. The implementation can be extended later as needed. RFC: https://discourse.llvm.org/t/rfc-llvm-objcopy-feature-for-editing-notes/83491
2025-01-23Revert "[llvm-objcopy][ELF] Add an option to remove notes (#118739)"Igor Kudrin1-2/+0
This reverts commit 9324e6a7a5c5adc5b5c38c3e3cbecd7e1e98876a.
2025-01-23[llvm-objcopy][ELF] Add an option to remove notes (#118739)Igor Kudrin1-0/+2
This adds an option `--remove-note=[name/]type` to selectively delete notes in ELF files, where `type` is the numeric value of the note type and `name` is the name of the originator. The name can be omitted, in which case all notes of the specified type will be removed. For now, only `SHT_NOTE` sections that are not associated with segments are handled. The implementation can be extended later as needed. RFC: https://discourse.llvm.org/t/rfc-llvm-objcopy-feature-for-editing-notes/83491
2024-02-09[llvm-objcopy] Support SREC output format (#75874)quic-areg1-0/+1
Adds a new output target "srec" to write SREC files from ELF inputs. https://en.wikipedia.org/wiki/SREC_(file_format)
2024-01-11[llvm-driver] Fix usage of `InitLLVM` on Windows (#76306)Alexandre Ganea1-2/+0
Previously, some tools such as `clang` or `lld` which require strict order for certain command-line options, such as `clang -cc1` or `lld -flavor`, would not longer work on Windows, when these tools were linked as part of `llvm-driver`. This was caused by `InitLLVM` which was part of the `*_main()` function of these tools, which in turn calls `windows::GetCommandLineArguments`. That function completly replaces argc/argv by new UTF-8 contents, so any ajustements to argc/argv made by `llvm-driver` prior to calling these tools was reset. `InitLLVM` is now called by the `llvm-driver`. Any tool that participates in (or is part of) the `llvm-driver` doesn't call `InitLLVM` anymore.
2023-12-03[llvm] Stop including string (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-02-10[llvm-driver] Pass extra arguments to toolsAlex Brachet1-1/+2
Differential Revision: https://reviews.llvm.org/D137799
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-1/+1
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-06-06LLVM Driver Multicall toolChris Bieneman1-1/+1
This patch adds an llvm-driver multicall tool that can combine multiple LLVM-based tools. The build infrastructure is enabled for a tool by adding the GENERATE_DRIVER option to the add_llvm_executable CMake call, and changing the tool's main function to a canonicalized tool_name_main format (i.e. llvm_ar_main, clang_main, etc...). As currently implemented llvm-driver contains dsymutil, llvm-ar, llvm-cxxfilt, llvm-objcopy, and clang (if clang is included in the build). llvm-driver can be enabled from builds by setting LLVM_TOOL_LLVM_DRIVER_BUILD=On. There are several limitations in the current implementation, which can be addressed in subsequent patches: (1) the multicall binary cannot currently properly handle multi-dispatch tools. This means symlinking llvm-ranlib to llvm-driver will not properly result in llvm-ar's main being called. (2) the multicall binary cannot be comprised of tools containing conflicting cl::opt options as the global cl::opt option list cannot contain duplicates. These limitations can be addressed in subsequent patches. Differential revision: https://reviews.llvm.org/D109977
2022-04-26[llvm-objcopy][NFC] rename variable.Alexey Lapshin1-6/+7
2022-04-22[llvm-objcopy][NFC] refactor restoreStatOnFile out of llvm-objcopy.Alexey Lapshin1-59/+10
Functionality of restoreStatOnFile may be reused. Move it into FileUtilities.cpp. Create helper class FilePermissionsApplier to store and apply permissions. Differential Revision: https://reviews.llvm.org/D123821
2022-03-04[llvm] add -r functionality to llvm-bitcode-stripRichard Howell1-1/+1
This diff adds functionality to the llvm-bitcode-strip tool for stripping of LLVM bitcode sections. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D120669
2022-02-17[llvm-objcopy][NFC] Move core implementation of llvm-objcopy into separate ↵Alexey Lapshin1-142/+11
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
2021-12-09[llvm] Add null-termination capability to SmallVectorMemoryBufferJan Svoboda1-1/+2
Most of `MemoryBuffer` interfaces expose a `RequiresNullTerminator` parameter that's being used to: * determine how to open a file (`mmap` vs `open`), * assert newly initialized buffer indeed has an implicit null terminator. This patch adds the paramater to the `SmallVectorMemoryBuffer` constructors, meaning: * null terminator can now be added to `SmallVector`s that didn't have one before, * `SmallVectors` that had a null terminator before keep it even after the move. In line with existing code, the new parameter is defaulted to `true`. This patch makes sure all calls to the `SmallVectorMemoryBuffer` constructor set it to `false` to preserve the current semantics. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D115331
2021-06-25[llvm] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-1/+1
This is a mechanical change. This actually also renames the similarly named methods in the SmallString class, however these methods don't seem to be used outside of the llvm subproject, so this doesn't break building of the rest of the monorepo.
2021-06-21[llvm-objcopy] Internalize some symbolsFangrui Song1-11/+5
2021-06-21[llvm-objcopy] Delete empty namespace. NFCFangrui Song1-4/+0
2021-05-20[llvm-objcopy] Refactor CopyConfig structure.Alexey Lapshin1-40/+75
This patch prepares llvm-objcopy to move its implementation into a separate library. To make it possible it is necessary to minimize internal dependencies. Differential Revision: https://reviews.llvm.org/D99055
2021-04-12Fix chrome os failure after 021de7cf80268091cf13485a538b611b37d0b33e.Alexey Lapshin1-6/+6
chrome os build failed after D98511: https://bugs.chromium.org/p/chromium/issues/detail?id=1197970 This patch fixes permission issue appeared after D98511.
2021-03-22[llvm-objcopy][Support] move writeToOutput helper function to Support.Alexey Lapshin1-31/+3
writeToOutput function is useful when it is necessary to create different kinds of streams(based on stream name) and when we need to use a temporary file while writing(which would be renamed into the resulting file in a success case). This patch moves the writeToStream helper into the Support library. Differential Revision: https://reviews.llvm.org/D98426
2021-03-18[llvm-objcopy] remove split dwo file creation from executeObjcopyOnBinary.Alexey Lapshin1-26/+50
This patch removes creation of the resulting file from the executeObjcopyOnBinary() function. For the most use cases, the executeObjcopyOnBinary receives output file as a parameter - raw_ostream &Out. The splitting .dwo file is implemented differently: file containg .dwo tables is created inside executeObjcopyOnBinary(). When objcopy functionality would be moved into separate library, current implementation will become inconvenient. The goal of that refactoring is to separate concerns: It might be convenient to to do dwo tables splitting but to create resulting file differently. Differential Revision: https://reviews.llvm.org/D98582
2021-03-17[llvm-objcopy][NFC] Move ownership keeping code into restoreStatOnFile().Alexey Lapshin1-20/+12
The D93881 added functionality which preserve ownership for output file if llvm-objcopy is called under root. That code was added into the place where output file is created. The llvm-objcopy already has a function which sets/restores rights/permissions for the output file. That is the restoreStatOnFile() function. This patch moves code (preserving ownershipping) into the restoreStatOnFile() function. Differential Revision: https://reviews.llvm.org/D98511
2021-03-10[llvm-objcopy][NFC] replace class Buffer/MemBuffer/FileBuffer with streams.Alexey Lapshin1-24/+76
During D88827 it was requested to remove the local implementation of Memory/File Buffers: // TODO: refactor the buffer classes in LLVM to enable us to use them here // directly. This patch uses raw_ostream instead of Buffers. Generally, using streams could allow us to reduce memory usages. No need to load all data into the memory - the data could be streamed through a smaller buffer. Thus, this patch uses raw_ostream as an interface for output data: Error executeObjcopyOnBinary(CopyConfig &Config, object::Binary &In, raw_ostream &Out); Note 1. This patch does not change the implementation of Writers so that data would be directly stored into raw_ostream. This is assumed to be done later. Note 2. It would be better if Writers would be implemented in a such way that data could be streamed without seeking/updating. If that would be inconvenient then raw_ostream could be replaced with raw_pwrite_stream to have a possibility to seek back and update file headers. This is assumed to be done later if necessary. Note 3. Current FileOutputBuffer allows using a memory-mapped file. The raw_fd_ostream (which could be used if data should be stored in the file) does not allow us to use a memory-mapped file. Memory map functionality could be implemented for raw_fd_ostream: It is possible to add resize() method into raw_ostream. class raw_ostream { void resize(uint64_t size); } That method, implemented for raw_fd_ostream, could create a memory-mapped file. The streamed data would be written into that memory file then. Thus we would be able to use memory-mapped files with raw_fd_ostream. This is assumed to be done later if necessary. Differential Revision: https://reviews.llvm.org/D91028
2021-02-24[llvm-objcopy] If input=output, preserve umask bits, otherwise drop ↵Fangrui Song1-13/+11
S_ISUID/S_ISGID bits This makes the behavior similar to cp ``` chmod u+s,g+s,o+x a sudo llvm-strip a -o b // With this patch, b drops set-user-ID and set-group-ID bits. // sudo cp a b => b does not have set-user-ID or set-group-ID bits. ``` This also changes the behavior for the following case: ``` chmod u+s,g+s,o+x a llvm-strip a // a preserves set-user-ID and set-group-ID bits. // This matches binutils<2.36 and probably >=2.37. 2.36 and 2.36.1 have some compatibility issues. ``` Differential Revision: https://reviews.llvm.org/D97253
2021-02-12[llvm-objcopy] preserve file ownership when overwritten by rootJian Cai1-1/+4
As of binutils 2.36, GNU strip calls chown(2) for "sudo strip foo" and "sudo strip foo -o foo", but no "sudo strip foo -o bar" or "sudo strip foo -o ./foo". In other words, while "sudo strip foo -o bar" creates a new file bar with root access, "sudo strip foo" will keep the owner and group of foo unchanged. Currently llvm-objcopy and llvm-strip behave differently, always changing the owner and gropu to root. The discrepancy prevents Chrome OS from migrating to llvm-objcopy and llvm-strip as they change file ownership and cause intended users/groups to lose access when invoked by sudo with the following sequence (recommended in man page of GNU strip). 1.<Link the executable as normal.> 1.<Copy "foo" to "foo.full"> 1.<Run "strip --strip-debug foo"> 1.<Run "objcopy --add-gnu-debuglink=foo.full foo"> This patch makes llvm-objcopy and llvm-strip follow GNU's behavior. Link: crbug.com/1108880
2020-10-22[llvm-objcopy][NFC] Extract arg parsing logic into a helper functionKeith Smiley1-30/+26
This diff refactors the code which determines the tool type based on how llvm-objcopy is invoked (objcopy vs strip vs bitcode-strip vs install-name-tool). NFC. Test plan: make check-all Differential revision: https://reviews.llvm.org/D89713
2020-10-06[llvm-objcopy][MachO] Add support for universal binariesAlexander Shaposhnikov1-3/+23
This diff adds support for universal binaries to llvm-objcopy. This is a recommit of 32c8435ef70031 with the asan issue fixed. Test plan: make check-all Differential revision: https://reviews.llvm.org/D88400
2020-10-06Revert "[llvm-objcopy][MachO] Add support for universal binaries"Dmitri Gribenko1-23/+3
This reverts commit 32c8435ef70031d7bd3dce48e41bdce65747e123. It fails ASan, details in https://reviews.llvm.org/D88400.
2020-10-06Revert "[llvm-objcopy][MachO] Add missing std::move."Dmitri Gribenko1-1/+1
This reverts commit 6e25586990b93e2c9eaaa4f473b6720ccd646c46. It depends on 32c8435ef70031d7bd3dce48e41bdce65747e123, which I'm reverting due to ASan failures. Details in https://reviews.llvm.org/D88400.
2020-10-05[llvm-objcopy][MachO] Add missing std::move.Alexander Shaposhnikov1-1/+1
This change fixes the build issue introduced by 32c8435ef7 (detected by the buildbot fuchsia-x86_64-linux). Test plan: make check-all
2020-10-05[llvm-objcopy][MachO] Add support for universal binariesAlexander Shaposhnikov1-3/+23
This diff adds support for universal binaries to llvm-objcopy. Test plan: make check-all Differential revision: https://reviews.llvm.org/D88400
2020-10-02[llvm-objcopy][NFC] refactor error handling. part 3.Alexey Lapshin1-31/+0
Remove usages of special error reporting functions(error(), reportError()). Errors are reported as Expected<>/Error returning values. This part is for ELF subfolder of llvm-objcopy. Testing: check-all. Differential Revision: https://reviews.llvm.org/D87987
2020-09-18[llvm-objcopy][MachO] Add llvm-bitcode-strip driverAlexander Shaposhnikov1-6/+11
This diff adds llvm-bitcode-strip driver to llvm-objcopy. In the future this will enable us to build a replacement for the tool bitcode_strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D87212
2020-03-23[llvm-objcopy] Improve tool selection logic to recognize llvm-strip-$major ↵Fangrui Song1-5/+19
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-11Remove unused Endian.h includes, NFCReid Kleckner1-0/+1
Mainly avoids including Host.h everywhere: $ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 3141 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Host.h
2020-01-29[llvm-objcopy] Initial support for wasm in llvm-objcopyDerek Schuff1-1/+5
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-29Revert "[llvm-objcopy] Initial support for wasm in llvm-objcopy"Derek Schuff1-5/+1
This reverts commit a928d127a52a061733d2e42c4c9159a267f7dbd4. It seems to cause issues with big-endian architectures.
2020-01-28[llvm-objcopy] Initial support for wasm in llvm-objcopyDerek Schuff1-1/+5
Currently only supports simple copying, other operations to follow. Reviewers: sbc100, alexshap, jhenderson Differential Revision: https://reviews.llvm.org/D70930
2019-11-19Introduce llvm-install-name-toolAlexander Shaposhnikov1-5/+15
This diff adds a new "driver" for llvm-objcopy which is supposed to emulate the behavior of install-name-tool. This is a recommit of b5913e6 with ubsan, test dependencies issues fixed. Differential revision: https://reviews.llvm.org/D69146 Test plan: make check-all
2019-11-19Revert "Introduce llvm-install-name-tool"Alexander Shaposhnikov1-15/+5
This temporarily reverts the commit 88f00aef684ff84a6494e1f17d5466c5678f703d. The change broke the buildbot http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/36836
2019-11-19Introduce llvm-install-name-toolAlexander Shaposhnikov1-5/+15
This diff adds a new "driver" for llvm-objcopy which is supposed to emulate the behavior of install-name-tool. This is a recommit of b5913e6d2 with ubsan issues fixed. Differential revision: https://reviews.llvm.org/D69146 Test plan: make check-all
2019-11-06Revert "Introduce llvm-install-name-tool"Alexander Shaposhnikov1-15/+5
This reverts commit b5913e6d2f6d13fb753df701619731ca11936316.
2019-11-06Introduce llvm-install-name-toolAlexander Shaposhnikov1-5/+15
This diff adds a new "driver" for llvm-objcopy which is supposed to emulate the behavior of install-name-tool. Differential revision: https://reviews.llvm.org/D69146 Test plan: make check-all
2019-10-17[llvm-objcopy] Add support for shell wildcardsJordan Rupprecht1-1/+1
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags). The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag. Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway). Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap Reviewed By: MaskRay Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66613 llvm-svn: 375169
2019-09-24 [llvm-objcopy] Refactor ELF-specific config out to ELFCopyConfig. NFC.Seiya Nuta1-12/+17
Summary: This patch splits the command-line parsing into two phases: First, parse cross-platform options and leave ELF-specific options unparsed. Second, in the ELF implementation, parse ELF-specific options and construct ELFCopyConfig. Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich, MaskRay Reviewed By: alexshap, jhenderson, jakehehrlich, MaskRay Subscribers: mgorny, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67139 llvm-svn: 372712
2019-09-14[llvm-objcopy] Add support for response files in llvm-strip and llvm-objcopyMichael Pozulp1-2/+20
Summary: Addresses https://bugs.llvm.org/show_bug.cgi?id=42671 Reviewers: jhenderson, espindola, alexshap, rupprecht Reviewed By: jhenderson Subscribers: seiya, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65372 llvm-svn: 371911
2019-08-20[llvm-objcopy] Append '\n' to warning messagesFangrui Song1-1/+1
Currently the warning message of `llvm-strip %t.o %t.o` does not include the trailing newline. Fix this by appending a '\n'. This is the only warning llvm-objcopy and llvm-strip can issue. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D66475 llvm-svn: 369391