summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [llvm-objcopy] Skip --localize-symbol for undefined symbolsJordan Rupprecht2019-01-311-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Include the symbol being defined in the list of requirements for using --localize-symbol. This is used, for example, when someone is depending on two different projects that have the same (or close enough) method defined in each library, and using "-L sym" for a conflicting symbol in one of the libraries so that the definition from the other one is used. However, the library may have internal references to the symbol, which cause program crashes when those are used, i.e.: ``` $ cat foo.c int foo() { return 5; } $ cat bar.c int foo(); int bar() { return 2 * foo(); } $ cat foo2.c int foo() { /* Safer implementation */ return 42; } $ cat main.c int bar(); int main() { __builtin_printf("bar = %d\n", bar()); return 0; } $ ar rcs libfoo.a foo.o bar.o $ ar rcs libfoo2.a foo2.o # Picks the wrong foo() impl $ clang main.o -lfoo -lfoo2 -L. -o main # Picks the right foo() impl $ objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main # Links somehow, but crashes at runtime $ llvm-objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main ``` Reviewers: jhenderson, alexshap, jakehehrlich, espindola Subscribers: emaste, arichardson Differential Revision: https://reviews.llvm.org/D57417 llvm-svn: 352767
* [llvm-objcopy][NFC] More error propagation (linkToBuildIdDir)Jordan Rupprecht2019-01-301-13/+21
| | | | llvm-svn: 352640
* [llvm-objcopy] Support -X|--discard-locals.Jordan Rupprecht2019-01-301-3/+5
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 352626
* [llvm-objcopy][NFC] More error propagationJordan Rupprecht2019-01-301-25/+32
| | | | | | | | | | | | Summary: Do some more error cleanup, removing some dependencies from llvm-objcopy's error/reportError in [ELF/COFF]Objcopy methods. Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola Subscribers: emaste, arichardson Differential Revision: https://reviews.llvm.org/D57423 llvm-svn: 352625
* [llvm-objcopy] Implement --set-section-flags.Jordan Rupprecht2019-01-291-10/+24
| | | | | | | | | | | | | | | | | 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 llvm-svn: 352505
* [llvm-objcopy] Return Error from Buffer::allocate(), ↵Jordan Rupprecht2019-01-221-6/+12
| | | | | | | | | | | | | | | | | | | | | | | [ELF]Writer::finalize(), and [ELF]Writer::commit() Summary: This patch changes a few methods to return Error instead of manually calling error/reportError to abort. This will make it easier to extract into a library. Note that error() takes just a string (this patch also adds an overload that takes an Error), while reportError() takes string + [error/code]. To help unify things, use FileError to associate a given filename with an error. Note that this takes some special care (for now), e.g. calling reportError(FileName, <something that could be FileError>) will duplicate the filename. The goal is to eventually remove reportError() and have every error associated with a file to be a FileError, and just one error handling block at the tool level. This change was suggested in D56806. I took it a little further than suggested, but completely fixing llvm-objcopy will take a couple more patches. If this approach looks good, I'll commit this and apply similar patche(s) for the rest. This change is NFC in terms of non-error related code, although the error message changes in one context. Reviewers: alexshap, jhenderson, jakehehrlich, mstorsjo, espindola Reviewed By: alexshap, jhenderson Subscribers: llvm-commits, emaste, arichardson Differential Revision: https://reviews.llvm.org/D56930 llvm-svn: 351896
* [llvm-objcopy] Consistently use createStringError instead of ↵Martin Storsjo2019-01-221-5/+5
| | | | | | | | | | | | make_error<StringError> This was requested in the review of D57006. Also add missing quotes around symbol names in error messages. Differential Revision: https://reviews.llvm.org/D57014 llvm-svn: 351799
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | 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. llvm-svn: 351636
* [llvm-objcopy] Use SHT_NOTE for added note sections.Jordan Rupprecht2019-01-151-9/+13
| | | | | | | | | | | | | | | | | | | Summary: Fix llvm-objcopy to add .note sections as SHT_NOTEs. GNU objcopy overrides section flags for special sections. For `.note` sections (with the exception of `.note.GNU-stack`), SHT_NOTE is used. Many other sections are special cased by libbfd, but `.note` is the only special section I can seem to find being used with objcopy --add-section. See `.note` in context of the full list of special sections here: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=eb3e1828e9c651678b95a1dcbc3b124783d1d2be;hb=HEAD#l2675 Reviewers: jhenderson, alexshap, jakehehrlich, espindola Reviewed By: jhenderson Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D56570 llvm-svn: 351204
* [llvm-objcopy] Handle -O <format> flag.Jordan Rupprecht2019-01-071-2/+12
| | | | | | | | | | | | | | | | | 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 llvm-svn: 350541
* [binutils] NFC: fix clang-tidy warning: use empty() instead of size() == 0Jordan Rupprecht2018-12-201-1/+1
| | | | llvm-svn: 349710
* llvm-objcopy: Improve/simplify llvm::Error handling during notes iterationDavid Blaikie2018-12-111-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using an Error as an out parameter from an indirect operation like iteration as described in the documentation ( http://llvm.org/docs/ProgrammersManual.html#building-fallible-iterators-and-iterator-ranges ) seems to be a little fussy - so here's /one/ possible solution, though I'm not sure it's the right one. Alternatively such APIs may be better off being switched to a standard algorithm style, where they take a lambda to do the iteration work that is then called back into (eg: "Error e = obj.for_each_note([](const Note& N) { ... });"). This would be safer than having an unwritten assumption that the user of such an iteration cannot return early from the inside of the function - and must always exit through the gift shop... I mean error checking. (even though it's guaranteed that if you're mid-way through processing an iteration, it's not in an error state). Alternatively we'd need some other (the super untrustworthy/thing we've generally tried to avoid) error handling primitive that actually clears the error state entirely so it's safe to ignore. Fleshed this solution out a bit further during review - it now relies on op==/op!= comparison as the equivalent to "if (Err)" testing the Error. So just like an Error must be checked (even if it's in a success state), the Error hiding in the iterator must be checked after each increment (including by comparison with another iterator - perhaps this could be constrained to only checking if the iterator is compared to the end iterator? Not sure it's too important). So now even just creating the iterator and not incrementing it at all should still assert because the Error has not been checked. Reviewers: lhames, jakehehrlich Differential Revision: https://reviews.llvm.org/D55235 llvm-svn: 348811
* [llvm-objcopy] Change --only-keep to --only-sectionJake Ehrlich2018-12-061-2/+2
| | | | | | | | | | | | 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 llvm-svn: 348446
* [llvm-objcopy] Add --build-id-link-dir flagJake Ehrlich2018-12-031-1/+76
| | | | | | | | | | | | | | | 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 llvm-svn: 348174
* [llvm-objcopy] Delete redundant !Config.xx.empty() when followed by positive ↵Fangrui Song2018-11-291-11/+5
| | | | | | | | | | | | | | | | is_contained() check Summary: The original intention of !Config.xx.empty() was probably to emphasize the thing that is currently considered, but I feel the simplified form is actually easier to understand and it is also consistent with the call sites in other llvm components. Reviewers: alexshap, rupprecht, jakehehrlich, jhenderson, espindola Reviewed By: alexshap, rupprecht Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D55040 llvm-svn: 347891
* [llvm-objcopy] Rename --keep to --keep-section.Jordan Rupprecht2018-11-131-2/+2
| | | | | | | | | | | | | | | | 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 llvm-svn: 346782
* [llvm-objcopy] Don't copy Config when processing --keepFangrui Song2018-11-121-1/+1
| | | | llvm-svn: 346717
* [llvm-objcopy] Don't apply --localize flags to common symbolsJordan Rupprecht2018-11-011-4/+5
| | | | | | | | | | | | | | | | | Summary: --localize-symbol and --localize-hidden will currently localize common symbols. GNU objcopy will not localize these symbols even when explicitly requested, which seems reasonable; common symbols should always be global so they can be merged during linking. See PR39461 Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola Reviewed By: jakehehrlich, jhenderson, alexshap, MaskRay Subscribers: emaste, arichardson, alexshap, MaskRay, llvm-commits Differential Revision: https://reviews.llvm.org/D53782 llvm-svn: 345856
* [llvm-objcopy] Fix --keep-global-symbol/--globalize-symbol for undefined ↵Jordan Rupprecht2018-10-301-2/+4
| | | | | | | | | | | | | | | | symbols. Summary: --keep-global-symbol and --globalize-symbol don't make sense for undefined symbols, so it should be ignored for those symbols. This matches GNU objcopy behavior. Reviewers: jhenderson, alexshap, jakehehrlich, espindola Reviewed By: jhenderson, jakehehrlich Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D53733 llvm-svn: 345614
* [llvm-objcopy] Move elf-specific code into subfolderAlexander Shaposhnikov2018-10-291-0/+503
In this diff the elf-specific code is moved into the subfolder ELF (and factored out from llvm-objcopy.cpp). Test plan: make check-all Differential revision: https://reviews.llvm.org/D53790 llvm-svn: 345544
OpenPOWER on IntegriCloud