29 Commits

Author SHA1 Message Date
Jordan Rupprecht
30e91d46e1 [llvm-strip] Hook up (unimplemented) --only-keep-debug
For ELF, we accept but ignore --only-keep-debug. Do the same for llvm-strip.

COFF does implement this, so update the test that it is supported.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356207 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-14 21:51:42 +00:00
Jordan Rupprecht
86c9a48802 [llvm-objcopy] Cleanup errors from CopyConfig and remove llvm-objcopy.h dependency
error() was previously cleaned up from CopyConfig, but new uses were introduced.

This also tweaks the error message for --add-symbol to report all invalid flags.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356105 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-13 22:26:01 +00:00
George Rimar
de9aea9530 [llvm-objcopy] - Report "no zlib available" error properly when --compress-debug-sections is used.
If zlib is not available, and --compress-debug-sections is passed, 
we want to report an error. Currently, it is only reported for
--compress_debug_sections= form of the option.

Fixes the https://bugs.llvm.org/show_bug.cgi?id=40886.

I do not think there is a way to write a test for this.

Differential revision: https://reviews.llvm.org/D58909

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355391 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-05 11:32:14 +00:00
Eugene Leviant
1f205834bb [llvm-objcopy] Add --set-start, --change-start and --adjust-start
Differential revision: https://reviews.llvm.org/D58173


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354854 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-26 09:24:22 +00:00
Eugene Leviant
b5395dc0fc [llvm-objcopy] Add --add-symbol
Differential revision: https://reviews.llvm.org/D58234


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354787 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-25 14:12:41 +00:00
Jordan Rupprecht
7f352a421a [llvm-objcopy][NFC] Add std::move() to fix older BB
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354603 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 17:24:55 +00:00
Jordan Rupprecht
794244932b [llvm-objcopy][NFC] More error cleanup
Summary:
This removes calls to `error()`/`reportError()` in the main driver (llvm-objcopy.cpp) as well as the associated argv-parsing (CopyConfig.cpp). `logAllUnhandledErrors()` is now the main way to print errors.

There are still a few uses from within the per-arch drivers, so we can't delete them yet... but almost!

Reviewers: jhenderson, alexshap, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, jakehehrlich, jdoerfert, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354600 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 17:05:19 +00:00
Eugene Leviant
cb9edfda6c [llvm-objcopy] Add --strip-unneeded-symbol(s)
Differential revision: https://reviews.llvm.org/D58027


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353919 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-13 07:34:54 +00:00
Eugene Leviant
aed0779715 Small refactoring of FileError. NFC.
Differential revision: https://reviews.llvm.org/D57945


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353679 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-11 09:49:37 +00:00
Eugene Leviant
e436b1687a [llvm-objcopy] Add few file processing directives
Differential revision: https://reviews.llvm.org/D57877


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353521 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-08 14:37:54 +00:00
Eugene Leviant
5f86a06337 [llvm-objcopy] Add --redefine-syms
Differential revision: https://reviews.llvm.org/D57738


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353509 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-08 10:33:16 +00:00
Eugene Leviant
e9f465a6a8 [llvm-objcopy] Allow regular expressions in name comparison
Differential revision: https://reviews.llvm.org/D57517


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353289 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-06 11:00:07 +00:00
Jordan Rupprecht
aab380fa40 [llvm-objcopy][NFC] Use StringSaver for --keep-global-symbols
Summary: Use StringSaver/BumpPtrAlloc when parsing lines from --keep-global-symbols files. This allows us to consistently use StringRef for driver options, which avoids copying the full strings for each object copied, as well as simplifies part of D57517.

Reviewers: jhenderson, evgeny777, alexshap

Subscribers: jakehehrlich

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353068 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-04 18:38:00 +00:00
Eugene Leviant
9075f54623 [llvm-strip] Implement --keep-file-symbols
Differential revision: https://reviews.llvm.org/D57582


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352878 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 15:25:15 +00:00
Eugene Leviant
b23da425d4 [llvm-strip] Add --strip-symbol
Differential revision: https://reviews.llvm.org/D57440


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352746 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 12:16:20 +00:00
Jordan Rupprecht
a6189f1972 [llvm-objcopy] Support -X|--discard-locals.
Summary:
This adds support for the --discard-locals flag, which acts similarly to --discard-all, except it only applies to compiler-generated symbols (i.e. symbols starting with `.L` in ELF).

I am not sure about COFF local symbols: those appear to also use `.L` in most cases, but also use just `L` in other cases, so for now I am just leaving it unimplemented there.

Fixes PR36160

Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola

Reviewed By: jhenderson

Subscribers: llvm-commits, emaste, arichardson

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352626 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-30 14:58:13 +00:00
Jordan Rupprecht
d99c98b3dd [llvm-objcopy] Implement --set-section-flags.
Summary:
--set-section-flags is used to change the section flags (e.g. SHF_ALLOC) for given sections. The flags allowed are the same from the existing --rename-section=.old=.new[,flags] feature.

Additionally, make sure that --set-section-flag cannot be used with --rename-section (either the source or destination), since --rename-section accepts flags. This avoids ambiguity for something like "--rename-section=.foo=.bar,alloc --set-section-flag=.bar,code".

Reviewers: jhenderson, jakehehrlich, alexshap, espindola

Reviewed By: jhenderson, jakehehrlich

Subscribers: llvm-commits, emaste, arichardson

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352505 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-29 15:05:38 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Jordan Rupprecht
f570c1cad5 [llvm-objcopy] Handle -O <format> flag.
Summary:
The -O flag is currently being mostly ignored; it's only checked whether or not the output format is "binary". This adds support for a few formats (e.g. elf64-x86-64), so that when specified, the output can change between 32/64 bit and sizes/alignments are updated accordingly.

This fixes PR39135

Reviewers: jakehehrlich, jhenderson, alexshap, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350541 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-07 16:59:12 +00:00
Jake Ehrlich
beec7d4978 [llvm-objcopy] Change --only-keep to --only-section
I just hard core goofed when I wrote this and created a different name
for no good reason. I'm failry aware of most "fresh" users of llvm-objcopy
(that is, users which are not using it as a drop in replacement for GNU
objcopy) and can say that only "-j" is being used by such people so this
patch should strictly increase compatibility and not remove it.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348446 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-06 02:03:53 +00:00
Jake Ehrlich
14107a3c41 [llvm-objcopy] Add --build-id-link-dir flag
This flag does not exist in GNU objcopy but has a major use case.
Debugging tools support the .build-id directory structure to find
debug binaries. There is no easy way to build this structure up
however. One way to do it is by using llvm-readelf and some crazy
shell magic. This implements the feature directly. It is most often
the case that you'll want to strip a file and send the original to
the .build-id directory but if you just want to send a file to the
.build-id directory you can copy to /dev/null instead.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348174 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-03 19:49:23 +00:00
Martin Storsjo
3eeed747ee [llvm-objcopy] Hook up the -V alias to --version, output "GNU strip"
This allows libtool to detect the presence of llvm-strip and use
it with the options --strip-debug and --strip-unneeded.

Also hook up the -V alias for objcopy.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347731 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-28 06:51:50 +00:00
Jordan Rupprecht
65bac069a6 [llvm-objcopy] Rename --keep to --keep-section.
Summary:
llvm-objcopy/strip support `--keep` (for sections) and `--keep-symbols` (for symbols). For consistency and clarity, rename `--keep` to `--keep-section`.
In fact, for GNU compatability, -K is --keep-symbol, so it's weird that the alias `-K` is not the same as the short-ish `--keep`.

Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola

Reviewed By: jakehehrlich, MaskRay

Subscribers: emaste, arichardson, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346782 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-13 19:32:27 +00:00
Jordan Rupprecht
9a78ad0d49 [llvm-strip] Support --keep and --strip-all-gnu from llvm-objcopy
Summary: Add --keep and --strip-all-gnu from llvm-objcopy into llvm-strip.

Reviewers: jakehehrlich, jhenderson, alexshap

Reviewed By: jhenderson, alexshap

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345861 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 17:48:46 +00:00
Jordan Rupprecht
167fb18752 [llvm-objcopy] Support --{enable,disable}-deterministic-archives
Summary: ar and objcopy/strip all support configuring whether archives are written deterministically (timestamps/UIDs/GIDs/etc zero'd). This has been ported to llvm-ar (the U/D modifiers) but not yet to llvm-objcopy/strip.

Reviewers: jakehehrlich, jhenderson, alexshap

Reviewed By: jhenderson

Subscribers: ruiu, mgrang, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345859 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 17:36:37 +00:00
Jordan Rupprecht
c2e4d07208 [llvm-objcopy] Fix use-after-move clang-tidy warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345079 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-23 20:54:51 +00:00
Jordan Rupprecht
863ec6dadf [llvm-strip] Support -s alias for --strip-all. Make both strip and objcopy case sensitive to support both -s (--strip-all) and -S (--strip-debug).
Summary:
GNU strip supports both `-s` and `-S` as aliases for `--strip-all` and `--strip-debug`, respectfully.

As part of this, it turns out that strip/objcopy were accepting case insensitive command line args. I'm not sure if there was an explicit reason for this. The only others uses of this are llvm-cvtres/llvm-mt/llvm-lib, which are all tools specific for windows support. Forcing case sensitivity allows both aliases to exist, but seems like a good idea anyway.

And as a surprise test case adjustment, the llvm-strip unit test was running with `-keep=unavailable_symbol`, despite `keep` not be a valid flag for strip. This is because there is a flag `-K` which, when case insensitivity is permitted, allows it to be interpreted as `-K` = `eep=unavailable_symbol` (e.g. to allow `-Kfoo` == `--keep-symbol=foo`).

Reviewers: jakehehrlich, jhenderson, alexshap

Reviewed By: jakehehrlich

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345068 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-23 18:46:33 +00:00
Jordan Rupprecht
3b7de9d1bb [llvm-objcopy] Add -F|--target compatibility
Summary:
This change adds support for the GNU --target flag, which sets both --input-target and --output-target.

GNU objcopy doesn't do any checking for whether both --target and --{input,output}-target are used, and so it allows both, e.g. "--target A --output-target B" is equivalent to "--input-target A --output-target B" since the later command line flag would override earlier ones. This may be error prone, so I chose to implement it as an error if both are used. I'm not sure if anyone is actually using both.

Reviewers: jakehehrlich, jhenderson, alexshap

Reviewed By: jakehehrlich, alexshap

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344321 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-12 00:36:01 +00:00
Alexander Shaposhnikov
bd934ffaab [llvm-objcopy] Factor out CopyConfig
In this diff we move out CopyConfig from llvm-oobjcopy.cpp into a separate header CopyConfig.h
to enable us (in the future) reuse this class in the other implementations of objcopy (for coff, mach-o).
Additionally this enables us to unload the complexity from llvm-objcopy.cpp a little bit.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D53006


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344307 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-11 22:33:50 +00:00