summaryrefslogtreecommitdiffstats
path: root/lld/ELF/DriverUtils.cpp
Commit message (Collapse)AuthorAgeFilesLines
* LLD: Don't use the stderrOS stream in link before it's reassigned.James Y Knight2019-11-211-4/+4
| | | | | | | | | | | | | | | | Remove the lld::enableColors function, as it just obscures which stream it's affecting, and replace with explicit calls to the stream's enable_colors. Also, assign the stderrOS and stdoutOS globals first in link function, just to ensure nothing might use them. (Either change individually fixes the issue of using the old stream, but both together seems best.) Follow-up to b11386f9be9b2dc7276a758d64f66833da10bdea. Differential Revision: https://reviews.llvm.org/D70492
* Make it possible to redirect not only errs() but also outs()Rui Ueyama2019-11-181-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change is for those who use lld as a library. Context: https://reviews.llvm.org/D70287 This patch adds a new parmeter to lld::*::link() so that we can pass an raw_ostream object representing stdout. Previously, lld::*::link() took only an stderr object. Justification for making stdoutOS and stderrOS mandatory: I wanted to make link() functions to take stdout and stderr in that order. However, if we change the function signature from bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stderrOS = llvm::errs()); to bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stdoutOS = llvm::outs(), raw_ostream &stderrOS = llvm::errs()); , then the meaning of existing code that passes stderrOS silently changes (stderrOS would be interpreted as stdoutOS). So, I chose to make existing code not to compile, so that developers can fix their code. Differential Revision: https://reviews.llvm.org/D70292
* [ELF] Wrap things in `namespace lld { namespace elf {`, NFCFangrui Song2019-10-071-11/+14
| | | | | | | | | | | This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
* Re-submit r367649: Improve raw_ostream so that you can "write" colors using ↵Rui Ueyama2019-08-071-4/+4
| | | | | | | | | operator<< The original patch broke buildbots, perhaps because it changed the default setting whether colors are enabled or not. llvm-svn: 368131
* Revert r367649: Improve raw_ostream so that you can "write" colors using ↵Rui Ueyama2019-08-021-5/+4
| | | | | | | | operator<< This reverts commit r367649 in an attempt to unbreak Windows bots. llvm-svn: 367658
* Improve raw_ostream so that you can "write" colors using operator<<Rui Ueyama2019-08-021-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. raw_ostream supports ANSI colors so that you can write messages to the termina with colors. Previously, in order to change and reset color, you had to call `changeColor` and `resetColor` functions, respectively. So, if you print out "error: " in red, for example, you had to do something like this: OS.changeColor(raw_ostream::RED); OS << "error: "; OS.resetColor(); With this patch, you can write the same code as follows: OS << raw_ostream::RED << "error: " << raw_ostream::RESET; 2. Add a boolean flag to raw_ostream so that you can disable colored output. If you disable colors, changeColor, operator<<(Color), resetColor and other color-related functions have no effect. Most LLVM tools automatically prints out messages using colors, and you can disable it by passing a flag such as `--disable-colors`. This new flag makes it easy to write code that works that way. Differential Revision: https://reviews.llvm.org/D65564 llvm-svn: 367649
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-111-6/+6
| | | | | | | | | | | This patch does the same thing as r365595 to other subdirectories, which completes the naming style change for the entire lld directory. With this, the naming style conversion is complete for lld. Differential Revision: https://reviews.llvm.org/D64473 llvm-svn: 365730
* [Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama2019-07-101-90/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
* lld, llvm-dlltool, llvm-lib: Use getAsString() instead of getSpelling() for ↵Nico Weber2019-07-051-3/+3
| | | | | | | | | | | | | | | printing unknown args Since OPT_UNKNOWN args never have any values and consist only of spelling (and are never aliased), this doesn't make any difference in practice, but it's more consistent with Arg's guidance to use getAsString() for diagnostics, and it matches what clang does. Also tweak two tests to use an unknown option that contains '=' for additional coverage while here. (The new tests pass fine with the old code too though.) llvm-svn: 365200
* Make joined instances of JoinedOrSeparate flags point to the unaliased args, ↵Nico Weber2019-07-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | like all other arg types do This fixes an 8-year-old regression. r105763 made it so that aliases always refer to the unaliased option – but it missed the "joined" branch of JoinedOrSeparate flags. (r162231 then made the Args classes non-virtual, and r169344 moved them from clang to llvm.) Back then, there was no JoinedOrSeparate flag that was an alias, so it wasn't observable. Now /U in CLCompatOptions is a JoinedOrSeparate alias in clang, and warn_slash_u_filename incorrectly used the aliased arg id (using the unaliased one isn't really a regression since that warning checks if the undefined macro contains slash or backslash and only then emits the warning – and no valid use will pass "-Ufoo/bar" or similar). Also, lld has many JoinedOrSeparate aliases, and due to this bug it had to explicitly call `getUnaliasedOption()` in a bunch of places, even though that shouldn't be necessary by design. After this fix in Option, these calls really don't have an effect any more, so remove them. No intended behavior change. (I accidentally fixed this bug while working on PR29106 but then wondered why the warn_slash_u_filename broke. When I figured it out, I thought it would make sense to land this in a separate commit.) Differential Revision: https://reviews.llvm.org/D64156 llvm-svn: 365186
* [ELF] Implement Dependent Libraries FeatureBen Dunbobbin2019-05-171-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements a limited form of autolinking primarily designed to allow either the --dependent-library compiler option, or "comment lib" pragmas ( https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically add the specified library to the link when processing the input file generated by the compiler. Currently this extension is unique to LLVM and LLD. However, care has been taken to design this feature so that it could be supported by other ELF linkers. The design goals were to provide: - A simple linking model for developers to reason about. - The ability to to override autolinking from the linker command line. - Source code compatibility, where possible, with "comment lib" pragmas in other environments (MSVC in particular). Dependent library support is implemented differently for ELF platforms than on the other platforms. Primarily this difference is that on ELF we pass the dependent library specifiers directly to the linker without manipulating them. This is in contrast to other platforms where they are mapped to a specific linker option by the compiler. This difference is a result of the greater variety of ELF linkers and the fact that ELF linkers tend to handle libraries in a more complicated fashion than on other platforms. This forces us to defer handling the specifiers to the linker. In order to achieve a level of source code compatibility with other platforms we have restricted this feature to work with libraries that meet the following "reasonable" requirements: 1. There are no competing defined symbols in a given set of libraries, or if they exist, the program owner doesn't care which is linked to their program. 2. There may be circular dependencies between libraries. The binary representation is a mergeable string section (SHF_MERGE, SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES (0x6fff4c04). The compiler forms this section by concatenating the arguments of the "comment lib" pragmas and --dependent-library options in the order they are encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs sections with the normal mergeable string section rules. As an example, #pragma comment(lib, "foo") would result in: .section ".deplibs","MS",@llvm_dependent_libraries,1 .asciz "foo" For LTO, equivalent information to the contents of a the .deplibs section can be retrieved by the LLD for bitcode input files. LLD processes the dependent library specifiers in the following way: 1. Dependent libraries which are found from the specifiers in .deplibs sections of relocatable object files are added when the linker decides to include that file (which could itself be in a library) in the link. Dependent libraries behave as if they were appended to the command line after all other options. As a consequence the set of dependent libraries are searched last to resolve symbols. 2. It is an error if a file cannot be found for a given specifier. 3. Any command line options in effect at the end of the command line parsing apply to the dependent libraries, e.g. --whole-archive. 4. The linker tries to add a library or relocatable object file from each of the strings in a .deplibs section by; first, handling the string as if it was specified on the command line; second, by looking for the string in each of the library search paths in turn; third, by looking for a lib<string>.a or lib<string>.so (depending on the current mode of the linker) in each of the library search paths. 5. A new command line option --no-dependent-libraries tells LLD to ignore the dependent libraries. Rationale for the above points: 1. Adding the dependent libraries last makes the process simple to understand from a developers perspective. All linkers are able to implement this scheme. 2. Error-ing for libraries that are not found seems like better behavior than failing the link during symbol resolution. 3. It seems useful for the user to be able to apply command line options which will affect all of the dependent libraries. There is a potential problem of surprise for developers, who might not realize that these options would apply to these "invisible" input files; however, despite the potential for surprise, this is easy for developers to reason about and gives developers the control that they may require. 4. This algorithm takes into account all of the different ways that ELF linkers find input files. The different search methods are tried by the linker in most obvious to least obvious order. 5. I considered adding finer grained control over which dependent libraries were ignored (e.g. MSVC has /nodefaultlib:<library>); however, I concluded that this is not necessary: if finer control is required developers can fall back to using the command line directly. RFC thread: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131004.html. Differential Revision: https://reviews.llvm.org/D60274 llvm-svn: 360984
* Add typo correction for command-line flags to ELF and COFF lld driversNico Weber2019-05-071-2/+8
| | | | | | | | | | | | For lld-link, unknown '/'-style flags are treated as filenames on POSIX systems, so only '-'-style flags get typo correction for now. This matches clang-cl. PR37006. Differential Revision: https://reviews.llvm.org/D61443 llvm-svn: 360145
* Remove a function from header and move the implementation to a .cpp file. NFC.Rui Ueyama2019-02-221-0/+6
| | | | llvm-svn: 354703
* 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
* Eliminate dependency to formatv(). NFC.Rui Ueyama2018-10-101-4/+3
| | | | llvm-svn: 344177
* Adapt OptTable::PrintHelp change in D51009Fangrui Song2018-10-101-2/+4
| | | | | | | | | | | | | | Summary: Before, OptTable::PrintHelp append "[options] <inputs>" to its parameter `Help`. It is more flexible to change its semantic to `Usage` and let user customize the usage line. Reviewers: rupprecht, ruiu, espindola Reviewed By: rupprecht Subscribers: emaste, sbc100, arichardson, aheejin, llvm-commits Differential Revision: https://reviews.llvm.org/D53054 llvm-svn: 344099
* [ELF] Use search paths for --version-script=Fangrui Song2018-07-251-4/+4
| | | | | | | | | | | | Summary: This behavior matches ld.bfd -Ld --version-script=t.script a.o Reviewers: ruiu, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D49820 llvm-svn: 337969
* Handle --plugin-opt= options as alias options.Rui Ueyama2018-05-221-0/+24
| | | | | | | | | | Previously, we had a loop to iterate over options starting with `--plugin-opt=` and parse them by hand. But we can make OptTable do that job for us. Differential Revision: https://reviews.llvm.org/D47167 llvm-svn: 332935
* lld-link: Add --color-diagnostics(={always,never,auto})?, ↵Nico Weber2018-05-101-4/+4
| | | | | | | | | | | | | | | --no-color-diagnostics flags. This is most useful when using lld-link on a non-Win host (but it might become useful on Windows too if lld also grows a fansi-escape-codes flag). Also make the help for --color-diagnostic mention the valid values in ELF and wasm, and print the flag name with two dashes in diags, since the one-dash form is seen as a list of many one-letter flags in some contexts. https://reviews.llvm.org/D46693 llvm-svn: 332012
* Simplify libtool compatibility hack.Rafael Espindola2018-02-071-7/+1
| | | | | | | | | | | | | I tested that if I remove "elf" from the message, building a program that uses libtool prints checking whether to build shared libraries... no but with this patch it still prints checking whether to build shared libraries... yes llvm-svn: 324428
* Store just argv[0] in Config.Rafael Espindola2018-02-061-4/+4
| | | | | | | Having the full argv there seems in conflict with the desire to parse all command line options in the Driver. llvm-svn: 324418
* Hide the --full-shutdown option.Rafael Espindola2018-02-061-0/+1
| | | | llvm-svn: 324365
* Remove redundant local variables.Rui Ueyama2017-12-111-3/+2
| | | | llvm-svn: 320436
* toString function take a const refs where possibleSam Clegg2017-12-051-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40824 llvm-svn: 319787
* Move Memory.{h,cpp} to Common.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
* [ELF] Fix rewriting of --sysroot in reproducer tarsAlexander Richardson2017-11-201-0/+1
| | | | | | | | | | | | | | | | | | Summary: I noticed that the reproducers files I was getting from building CheriBSD didn't work because the --sysroot option was not being rewritten. I've updated the test to also verify that the rewritten path matches uses a FileCheck capature instead of a {{.+}} regex Reviewers: ruiu Reviewed By: ruiu Subscribers: llvm-commits, emaste Differential Revision: https://reviews.llvm.org/D40125 llvm-svn: 318656
* [ELF] Fall back to search dirs for linker scripts specified with -TAlexander Richardson2017-11-201-0/+9
| | | | | | | | | | | | | | | | | | | | Summary: This matches the behaviour of ld.bfd: https://sourceware.org/binutils/docs/ld/Options.html#Options If scriptfile does not exist in the current directory, ld looks for it in the directories specified by any preceding '-L' options. Multiple '-T' options accumulate. Reviewers: ruiu, grimar Reviewed By: ruiu, grimar Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D40129 llvm-svn: 318655
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-20/+19
| | | | | | | | | | | | | | | | | | | Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
* Move new lld's code to Common subdirectory.Rui Ueyama2017-10-021-2/+2
| | | | | | | | | | New lld's files are spread under lib subdirectory, and it isn't easy to find which files are actually maintained. This patch moves maintained files to Common subdirectory. Differential Revision: https://reviews.llvm.org/D37645 llvm-svn: 314719
* [ELF] Rewrite --symbol-ordering-file path in reproducerJames Henderson2017-09-061-0/+1
| | | | | | | | | | | | The --symbol-ordering-file path was not being rewritten in the response file when using --reproduce. This patch adds this to the list of switches that are rewritten, so that the path is somewhere within the reproducer directory tree. Reviewers: ruiu Differential Revision: https://reviews.llvm.org/D37480 llvm-svn: 312626
* [ELF] - Print options aliases in --helpGeorge Rimar2017-07-261-1/+2
| | | | | | | | | | This is PR30422, previously LLD did not render all option aliases in --help. With this patch it will. Differential revision: https://reviews.llvm.org/D35477 llvm-svn: 309089
* [ELF] - Introduce multiclass Eq helper for Options.tdGeorge Rimar2017-07-211-1/+1
| | | | | | | | | Eq helper allows to define `XXX` and `XXX=` options forms easily. Patch adds testcases for few aliases. Differential revision: https://reviews.llvm.org/D35619 llvm-svn: 308752
* Add the --chroot option for --reproduce.Rui Ueyama2017-07-201-0/+1
| | | | | | | | | | | | | | | Summary: If the linker is invoked with `--chroot /foo` and `/bar/baz.o`, it tries to read the file from `/foo/bar/baz.o`. This feature is useful when you are dealing with files created by the --reproduce option. Reviewers: grimar Subscribers: llvm-commits, emaste Differential Revision: https://reviews.llvm.org/D35517 llvm-svn: 308646
* Fix one more occurrence of getOption().getID().Rui Ueyama2017-07-191-2/+1
| | | | llvm-svn: 308523
* Fix argument numbersing in OPTION macroSam Clegg2017-06-201-3/+3
| | | | | | | | | | The option numbers in the macro were off by one which leads to some confusion. There are actually 12 arguments to this macro. Differential Revision: https://reviews.llvm.org/D34413 llvm-svn: 305823
* [GSoC] Flag value completion for clangYuka Takahashi2017-06-201-2/+2
| | | | | | | | | | | | This is patch for GSoC project, bash-completion for clang. To use this on bash, please run `source clang/utils/bash-autocomplete.sh`. bash-autocomplete.sh is code for bash-completion. In this patch, Options.td was mainly changed in order to add value class in Options.inc. llvm-svn: 305805
* Sort.Rui Ueyama2017-03-271-5/+5
| | | | llvm-svn: 298829
* Use raw_fd_ostream::has_colors instead of StandardErrHasColors().Rui Ueyama2017-03-241-4/+2
| | | | | | I just didn't know that raw_fd_ostream has has_colors() function. llvm-svn: 298749
* [ELF] Print two more MIPS targets "supported" by LLDSimon Atanasyan2017-03-231-1/+2
| | | | | | These targets are related to MIPS N32 ABI. llvm-svn: 298591
* Refine comment.Rui Ueyama2017-03-231-2/+2
| | | | llvm-svn: 298571
* Print out "suppoted targets".Rui Ueyama2017-03-231-0/+13
| | | | | | | | | This is to improve compatibility with GNU Libtool that expect /supported targets:.* elf/ in a message for the -help option. Differential Revision: https://reviews.llvm.org/D31208 llvm-svn: 298568
* Strip file path from the -o option while creating reproduce.txt.Rafael Espindola2017-02-011-0/+7
| | | | | | | | | | | | | | | This is a fix for Bugzilla 28579. The problem is that in --reproduce links the file path in -o option is copied verbatim. When "lld @response.txt" link is run against the extracted test case, if -o contains anything other that a plain file name, the link will likely fail because the target directory in -o may not exists. Stripping the directory path will create the output file in the top level test directory. Patch by Dmitry Mikulin! llvm-svn: 293792
* Remove unused #include.Rui Ueyama2017-01-261-1/+0
| | | | llvm-svn: 293144
* Rename lld::stringize -> lld::toString.Rui Ueyama2017-01-061-1/+1
| | | | llvm-svn: 291223
* Make -color-diagnostics an alias to -color-diagnostics=always.Rui Ueyama2016-12-221-2/+5
| | | | | | | | Previously, that was an alias to -color-diagnostics=auto. However, Clang's -fcolor-diagnostics is an alias to -fcolor-diagnostics=always, so that was confusing. This patch fixes that issue. llvm-svn: 290332
* Set Config->ColorDiagnostics early so that all error messages are colored.Rui Ueyama2016-12-201-3/+27
| | | | | | | | | Previously, some errors that were checked before we set to Config->ColorDiagnostics weren't colored. This patch moves the code to set the variable so that such error messages are colored just like other error messages. llvm-svn: 290157
* Remove lld/Support/Memory.h.Rui Ueyama2016-12-181-1/+1
| | | | | | | | | | | | I thought for a while about how to remove it, but it looks like we can just copy the file for now. Of course I'm not happy about that, but it's just less than 50 lines of code, and we already have duplicate code in Error.h and some other places. I want to solve them all at once later. Differential Revision: https://reviews.llvm.org/D27819 llvm-svn: 290062
* Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.Rui Ueyama2016-12-081-1/+1
| | | | llvm-svn: 289084
* Change the implementation of --dynamic-list to use linker script parsing.Rafael Espindola2016-12-081-26/+0
| | | | | | | | | | | | | | | | | | | | | | | | | The feature is documented as ----------------------------- The format of the dynamic list is the same as the version node without scope and node name. See *note VERSION:: for more information. -------------------------------- And indeed qt uses a dynamic list with an 'extern "C++"' in it. With this patch we support that The change to gc-sections-shared makes us match bfd. Just because we kept bar doesn't mean it has to be in the dynamic symbol table. The changes to invalid-dynamic-list.test and reproduce.s are because of the new parser. The changes to version-script.s are the only case where we change behavior with regards to bfd, but I would like to see a mix of --version-script and --dynamic-list used in the wild before complicating the code. llvm-svn: 289082
* [ELF] Better error reporting for linker scriptsEugene Leviant2016-11-211-2/+2
| | | | | | Differential revision: https://reviews.llvm.org/D26795 llvm-svn: 287547
OpenPOWER on IntegriCloud