summaryrefslogtreecommitdiffstats
path: root/clang/test/Modules/autolink.m
Commit message (Collapse)AuthorAgeFilesLines
* [ELF] Implement Dependent Libraries FeatureBen Dunbobbin2019-05-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* CodeGen: fix autolink emission on ELFSaleem Abdulrasool2019-01-051-2/+2
| | | | | | | | | The autolinking extension for ELF uses a slightly different format for encoding the autolink information compared to COFF and MachO. Account for this in the CGM to ensure that we do not assert when emitting assembly or an object file. llvm-svn: 350476
* IR: Replace the "Linker Options" module flag with "llvm.linker.options" ↵Peter Collingbourne2017-06-121-4/+2
| | | | | | | | | | named metadata. The new metadata is easier to manipulate than module flags. Differential Revision: https://reviews.llvm.org/D31349 llvm-svn: 305227
* [modules] Simplify -cc1 interface for enabling implicit module maps.Richard Smith2015-06-161-3/+3
| | | | | | | | | | | | | We used to have a flag to enable module maps, and two more flags to enable implicit module maps. This is all redundant; we don't need any flag for enabling module maps in the abstract, and we don't usually have -fno- flags for -cc1. We now have just a single flag, -fimplicit-module-maps, that enables implicitly searching the file system for module map files and loading them. The driver interface is unchanged for now. We should probably rename -fmodule-maps to -fimplicit-module-maps at some point. llvm-svn: 239789
* Add PS4's autolink syntax to autolink.m's CHECK lines.Filipe Cabecinhas2015-02-281-2/+2
| | | | llvm-svn: 230841
* IR: Make metadata typeless in assembly, clang sideDuncan P. N. Exon Smith2014-12-151-8/+8
| | | | | | Match LLVM changes from r224257. llvm-svn: 224259
* Improve robustness of tests for module flags metadataOliver Stannard2014-06-191-2/+2
| | | | | | | Fix clang tests to not break if the ID numbers of module flags metadata nodes change. llvm-svn: 211276
* Fix autolinking when modules are imported in pch filesBen Langmuir2014-01-311-3/+9
| | | | | | | | | | | | Add the ImportDecl to the set of interesting delcarations that are deserialized eagerly when an AST file is loaded (rather than lazily like most decls). This is required to get auto linking to work when there is no explicit import in the main file. Also resolve a FIXME to rename 'ExternalDefinitions', since that is only one of the things that need eager deserialization. The new name is 'EagerlyDeserializedDecls'. The corresponding AST bitcode is also renamed. llvm-svn: 200505
* Suffixing #pragma comment(lib) library names with .lib if necessary. This ↵Aaron Ballman2013-05-241-1/+1
| | | | | | matches MSVC behavior, as well as allows us to properly link libraries such as the ones provided by the MSDN examples. llvm-svn: 182647
* Forward #pragma comment(lib/linker) through as flags metadataReid Kleckner2013-05-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: Most of this change is wiring the pragma all the way through from the lexer, parser, and sema to codegen. I considered adding a Decl AST node for this, but it seemed too heavyweight. Mach-O already uses a metadata flag called "Linker Options" to do this kind of auto-linking. This change follows that pattern. LLVM knows how to forward the "Linker Options" metadata into the COFF .drectve section where these flags belong. ELF support is not implemented, but possible. This is related to auto-linking, which is http://llvm.org/PR13016. CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D723 llvm-svn: 181426
* [Modules] Convert module specific -fno-modules-autolink into -fno-autolink.Daniel Dunbar2013-04-161-1/+5
| | | | | | | | | - There is no reason to have a modules specific flag for disabling autolinking. Instead, convert the existing flag into -fno-autolink (which should cover other autolinking code generation paths like #pragmas if and when we support them). llvm-svn: 179612
* Rename -fmodule-cache-path <blah> to -fmodules-cache-path=<blah> for ↵Douglas Gregor2013-02-071-1/+1
| | | | | | consistency. llvm-svn: 174645
* Add a comment for DanielDouglas Gregor2013-01-171-0/+2
| | | | llvm-svn: 172695
* [IRgen] Update modules autolink metadata to use module flags (as now specifiedDaniel Dunbar2013-01-171-1/+3
| | | | | | in the LangRef). llvm-svn: 172692
* Add -fmodules-autolink/-fno-modules-autolink (defaults to on) so thatDouglas Gregor2013-01-161-1/+1
| | | | | | users can explicitly enable/disable modules autolinking. llvm-svn: 172592
* Topologically sort the link options generated for modules based onDouglas Gregor2013-01-141-3/+8
| | | | | | | module-import dependencies, so we'll get the link order correct for those silly linkers that need it. llvm-svn: 172459
* When forming the link options for an imported module, also include theDouglas Gregor2013-01-141-4/+5
| | | | | | link options for the modules it imports. llvm-svn: 172448
* Switch autolinking metadata format over to actual linker options, e.g.,Douglas Gregor2013-01-141-5/+5
| | | | | | | | | | | | | | | | | | | !0 = metadata !{metadata !"-lautolink"} !1 = metadata !{metadata !"-framework", metadata !"autolink_framework"} referenced from llvm.module.linkoptions, e.g., !llvm.module.linkoptions = !{!0, !1, !2, !3} This conceptually moves the logic for figuring out the syntax the linker will accept from LLVM into Clang. Moreover, it makes it easier to support MSVC's #pragma comment(linker, "some option") in the future, should anyone care to do so. llvm-svn: 172441
* Infer "link" lines for top-level frameworks. Essentially, a frameworkDouglas Gregor2013-01-141-1/+13
| | | | | | | | will have a shared library with the same name as its framework (and no suffix!) within its .framework directory. Detect this both when inferring the whole top-level framework and when parsing a module map. llvm-svn: 172439
* Implement parsing, AST, (de-)serialization, and placeholder globalDouglas Gregor2013-01-141-0/+18
metadata for linking against the libraries/frameworks for imported modules. The module map language is extended with a new "link" directive that specifies what library or framework to link against when a module is imported, e.g., link "clangAST" or link framework "MyFramework" Importing the corresponding module (or any of its submodules) will eventually link against the named library/framework. For now, I've added some placeholder global metadata that encodes the imported libraries/frameworks, so that we can test that this information gets through to the IR. The format of the data is still under discussion. llvm-svn: 172437
OpenPOWER on IntegriCloud