]> granicus.if.org Git - llvm/commitdiff
[ELF] Implement Dependent Libraries Feature
authorBen Dunbobbin <bd1976llvm@gmail.com>
Fri, 17 May 2019 03:44:15 +0000 (03:44 +0000)
committerBen Dunbobbin <bd1976llvm@gmail.com>
Fri, 17 May 2019 03:44:15 +0000 (03:44 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360984 91177308-0d34-0410-b5e6-96231b3b80d8

22 files changed:
docs/Extensions.rst
docs/LangRef.rst
include/llvm-c/lto.h
include/llvm/BinaryFormat/ELF.h
include/llvm/LTO/LTO.h
include/llvm/LTO/legacy/LTOModule.h
include/llvm/Object/IRSymtab.h
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/LTO/LTO.cpp
lib/LTO/LTOModule.cpp
lib/MC/MCParser/ELFAsmParser.cpp
lib/MC/MCSectionELF.cpp
lib/Object/ELF.cpp
lib/Object/IRSymtab.cpp
lib/ObjectYAML/ELFYAML.cpp
test/Feature/elf-deplibs.ll [new file with mode: 0644]
test/LTO/Resolution/X86/symtab-elf.ll
test/MC/ELF/section.s
test/Object/X86/irsymtab.ll
tools/llvm-lto2/llvm-lto2.cpp
tools/llvm-readobj/ELFDumper.cpp
tools/lto/lto.cpp

index fac2289921ecc0f2d8c7393f5480d6cee7f06091..8543ac611850605a477727041d71c4e173eee893 100644 (file)
@@ -285,6 +285,26 @@ The following directives are specified:
     The paramter identifies an additional library search path to be considered
     when looking up libraries after the inclusion of this option.
 
+``SHT_LLVM_DEPENDENT_LIBRARIES`` Section (Dependent Libraries)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+This section contains strings specifying libraries to be added to the link by
+the linker.
+
+The section should be consumed by the linker and not written to the output.
+
+The strings are encoded as standard null-terminated UTF-8 strings.
+
+For example:
+
+.. code-block:: gas
+
+  .section ".deplibs","MS",@llvm_dependent_libraries,1
+  .asciz "library specifier 1"
+  .asciz "library specifier 2"
+
+The interpretation of the library specifiers is defined by the consuming linker.
+
 ``SHT_LLVM_CALL_GRAPH_PROFILE`` Section (Call Graph Profile)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
index af6e484c4b8923f6c885e8500ee807a840b25abb..bfe0a0ab9fecf9d2ab24d8a19a73c85a988311a0 100644 (file)
@@ -6081,10 +6081,10 @@ enum is the smallest type which can represent all of its values::
 Automatic Linker Flags Named Metadata
 =====================================
 
-Some targets support embedding flags to the linker inside individual object
+Some targets support embedding of flags to the linker inside individual object
 files. Typically this is used in conjunction with language extensions which
-allow source files to explicitly declare the libraries they depend on, and have
-these automatically be transmitted to the linker via object files.
+allow source files to contain linker command line options, and have these
+automatically be transmitted to the linker via object files.
 
 These flags are encoded in the IR using named metadata with the name
 ``!llvm.linker.options``. Each operand is expected to be a metadata node
@@ -6095,8 +6095,8 @@ For example, the following metadata section specifies two separate sets of
 linker options, presumably to link against ``libz`` and the ``Cocoa``
 framework::
 
-    !0 = !{ !"-lz" },
-    !1 = !{ !"-framework", !"Cocoa" } } }
+    !0 = !{ !"-lz" }
+    !1 = !{ !"-framework", !"Cocoa" }
     !llvm.linker.options = !{ !0, !1 }
 
 The metadata encoding as lists of lists of options, as opposed to a collapsed
@@ -6109,6 +6109,28 @@ Each individual option is required to be either a valid option for the target's
 linker, or an option that is reserved by the target specific assembly writer or
 object file emitter. No other aspect of these options is defined by the IR.
 
+Dependent Libs Named Metadata
+=============================
+
+Some targets support embedding of strings into object files to indicate
+a set of libraries to add to the link. Typically this is used in conjunction
+with language extensions which allow source files to explicitly declare the
+libraries they depend on, and have these automatically be transmitted to the
+linker via object files.
+
+The list is encoded in the IR using named metadata with the name
+``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
+which should contain a single string operand.
+
+For example, the following metadata section contains two library specfiers::
+
+    !0 = !{!"a library specifier"}
+    !1 = !{!"another library specifier"}
+    !llvm.dependent-libraries = !{ !0, !1 }
+
+Each library specifier will be handled independently by the consuming linker.
+The effect of the library specifiers are defined by the consuming linker.
+
 .. _summary:
 
 ThinLTO Summary
index a22f0bbade48c53ee1a596f6bd1e6e345c2af2af..5a33898d0f830090d2acfc8d3fc0fb33a3738908 100644 (file)
@@ -44,7 +44,7 @@ typedef bool lto_bool_t;
  * @{
  */
 
-#define LTO_API_VERSION 23
+#define LTO_API_VERSION 24
 
 /**
  * \since prior to LTO_API_VERSION=3
@@ -297,6 +297,14 @@ lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
 extern const char*
 lto_module_get_linkeropts(lto_module_t mod);
 
+/**
+* Returns the module's dependent library specifiers.
+*
+* \since LTO_API_VERSION=24
+*/
+extern const char*
+lto_module_get_dependent_libraries(lto_module_t mod);
+
 /**
  * Diagnostic severity.
  *
index 84f69666bb9d0e31674d3f8b92f3a4acdee1aadf..6ec924d08d1066d997cd286ec404b3901492ef10 100644 (file)
@@ -841,6 +841,7 @@ enum : unsigned {
   SHT_LLVM_CALL_GRAPH_PROFILE = 0x6fff4c02, // LLVM Call Graph Profile.
   SHT_LLVM_ADDRSIG = 0x6fff4c03,        // List of address-significant symbols
                                         // for safe ICF.
+  SHT_LLVM_DEPENDENT_LIBRARIES = 0x6fff4c04, // LLVM Dependent Library Specifiers.
   // Android's experimental support for SHT_RELR sections.
   // https://android.googlesource.com/platform/bionic/+/b7feec74547f84559a1467aca02708ff61346d2a/libc/include/elf.h#512
   SHT_ANDROID_RELR = 0x6fffff00,        // Relocation entries; only offsets.
index 76fa4f4dd62cf19556221813b56bbcc392e183f2..d3a0d3c37dccf63855bc2a5b6f85bbe398f8fb70 100644 (file)
@@ -115,6 +115,7 @@ private:
   std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
 
   StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
+  std::vector<StringRef> DependentLibraries;
   std::vector<StringRef> ComdatTable;
 
 public:
@@ -155,6 +156,9 @@ public:
   /// Returns linker options specified in the input file.
   StringRef getCOFFLinkerOpts() const { return COFFLinkerOpts; }
 
+  /// Returns dependent library specifiers from the input file.
+  ArrayRef<StringRef> getDependentLibraries() const { return DependentLibraries; }
+
   /// Returns the path to the InputFile.
   StringRef getName() const;
 
index 006521bf397834552227013c3106bcfff0e06f66..89d8682a207049170215c757eb33f77c6a5207c2 100644 (file)
@@ -47,6 +47,8 @@ private:
 
   std::string LinkerOpts;
 
+  std::string DependentLibraries;
+
   std::unique_ptr<Module> Mod;
   MemoryBufferRef MBRef;
   ModuleSymbolTable SymTab;
@@ -153,6 +155,8 @@ public:
 
   StringRef getLinkerOpts() { return LinkerOpts; }
 
+  StringRef getDependentLibraries() { return DependentLibraries; }
+
   const std::vector<StringRef> &getAsmUndefinedRefs() { return _asm_undefines; }
 
 private:
index 0601d995fd1832decdf79b9e0d2fe457c0e03898..0bbfc932493c6afd3bd91148e946f9a4c7bb4eb9 100644 (file)
@@ -125,12 +125,13 @@ struct Uncommon {
   Str SectionName;
 };
 
+
 struct Header {
   /// Version number of the symtab format. This number should be incremented
   /// when the format changes, but it does not need to be incremented if a
   /// change to LLVM would cause it to create a different symbol table.
   Word Version;
-  enum { kCurrentVersion = 1 };
+  enum { kCurrentVersion = 2 };
 
   /// The producer's version string (LLVM_VERSION_STRING " " LLVM_REVISION).
   /// Consumers should rebuild the symbol table from IR if the producer's
@@ -147,6 +148,9 @@ struct Header {
 
   /// COFF-specific: linker directives.
   Str COFFLinkerOpts;
+
+  /// Dependent Library Specifiers
+  Range<Str> DependentLibraries;
 };
 
 } // end namespace storage
@@ -231,6 +235,7 @@ class Reader {
   ArrayRef<storage::Comdat> Comdats;
   ArrayRef<storage::Symbol> Symbols;
   ArrayRef<storage::Uncommon> Uncommons;
+  ArrayRef<storage::Str> DependentLibraries;
 
   StringRef str(storage::Str S) const { return S.get(Strtab); }
 
@@ -251,6 +256,7 @@ public:
     Comdats = range(header().Comdats);
     Symbols = range(header().Symbols);
     Uncommons = range(header().Uncommons);
+    DependentLibraries = range(header().DependentLibraries);
   }
 
   using symbol_range = iterator_range<object::content_iterator<SymbolRef>>;
@@ -283,6 +289,16 @@ public:
 
   /// COFF-specific: returns linker options specified in the input file.
   StringRef getCOFFLinkerOpts() const { return str(header().COFFLinkerOpts); }
+
+  /// Returns dependent library specifiers
+  std::vector<StringRef> getDependentLibraries() const {
+    std::vector<StringRef> Specifiers;
+    Specifiers.reserve(DependentLibraries.size());
+    for (auto S : DependentLibraries) {
+      Specifiers.push_back(str(S));
+    }
+    return Specifiers;
+  }
 };
 
 /// Ephemeral symbols produced by Reader::symbols() and
index 436076f33b91849d3866fb3d668d5ccda51421cf..b3aa8c6e6343b6b71b4c5219b6ea03b2a01e2073 100644 (file)
@@ -271,6 +271,19 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
     }
   }
 
+  if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
+    auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
+                              ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
+
+    Streamer.SwitchSection(S);
+
+    for (const auto &Operand : DependentLibraries->operands()) {
+      Streamer.EmitBytes(
+          cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
+      Streamer.EmitIntValue(0, 1);
+    }
+  }
+
   unsigned Version = 0;
   unsigned Flags = 0;
   StringRef Section;
index 442c08532636f8f45138042c082afc7a4a8bc433..ce1b0a1e4f61337b91e12fcbf720a9efef4188cf 100644 (file)
@@ -425,6 +425,7 @@ Expected<std::unique_ptr<InputFile>> InputFile::create(MemoryBufferRef Object) {
   File->TargetTriple = FOrErr->TheReader.getTargetTriple();
   File->SourceFileName = FOrErr->TheReader.getSourceFileName();
   File->COFFLinkerOpts = FOrErr->TheReader.getCOFFLinkerOpts();
+  File->DependentLibraries = FOrErr->TheReader.getDependentLibraries();
   File->ComdatTable = FOrErr->TheReader.getComdatTable();
 
   for (unsigned I = 0; I != FOrErr->Mods.size(); ++I) {
index eb46b31d211e5843a829a078beaba74358f66eb3..83e9a09854cab8e81949ac488036f2e51d455f44 100644 (file)
@@ -646,5 +646,9 @@ void LTOModule::parseMetadata() {
     emitLinkerFlagsForGlobalCOFF(OS, Sym.symbol, TT, M);
   }
 
-  // Add other interesting metadata here.
+  // Dependent Libraries
+  raw_string_ostream OSD(DependentLibraries);
+  if (NamedMDNode *DependentLibraries = getModule().getNamedMetadata("llvm.dependent-libraries"))
+    for (MDNode *N : DependentLibraries->operands())
+      OSD << " " << cast<MDString>(N->getOperand(0))->getString();
 }
index 9e5b54a6881303587ca132a344fd8ef90f5448fc..48ced8d3dfa9cb6409bae14e71dfbe5706a7ed79 100644 (file)
@@ -615,6 +615,8 @@ EndStmt:
       Type = ELF::SHT_LLVM_LINKER_OPTIONS;
     else if (TypeName == "llvm_call_graph_profile")
       Type = ELF::SHT_LLVM_CALL_GRAPH_PROFILE;
+    else if (TypeName == "llvm_dependent_libraries")
+      Type = ELF::SHT_LLVM_DEPENDENT_LIBRARIES;
     else if (TypeName.getAsInteger(0, Type))
       return TokError("unknown section type");
   }
index e3c24efa93f31f864565f9d75a9f9e9f5384876c..569b6ba099747ab5d311868ee24d34fa6d197b82 100644 (file)
@@ -152,6 +152,8 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     OS << "llvm_linker_options";
   else if (Type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)
     OS << "llvm_call_graph_profile";
+  else if (Type == ELF::SHT_LLVM_DEPENDENT_LIBRARIES)
+    OS << "llvm_dependent_libraries";
   else
     report_fatal_error("unsupported type 0x" + Twine::utohexstr(Type) +
                        " for section " + getSectionName());
index d5d98126343e37e0fa80065935ca3488f0ed2403..951f4ae8f7eeac9a71d0d912fcd4f011423c455d 100644 (file)
@@ -253,6 +253,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
     STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LINKER_OPTIONS);
     STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_CALL_GRAPH_PROFILE);
     STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_ADDRSIG);
+    STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_DEPENDENT_LIBRARIES);
     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES);
     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);
     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef);
index e80eaf1db328fd31f74e8672532d405d9c5e7a2a..e4282b9d6bd32cdde99394e1c057dca279afcecb 100644 (file)
@@ -89,6 +89,8 @@ struct Builder {
   std::string COFFLinkerOpts;
   raw_string_ostream COFFLinkerOptsOS{COFFLinkerOpts};
 
+  std::vector<storage::Str> DependentLibraries;
+
   void setStr(storage::Str &S, StringRef Value) {
     S.Offset = StrtabBuilder.add(Value);
     S.Size = Value.size();
@@ -140,6 +142,20 @@ Error Builder::addModule(Module *M) {
     }
   }
 
+  if (TT.isOSBinFormatELF()) {
+    if (auto E = M->materializeMetadata())
+      return E;
+    if (NamedMDNode *N = M->getNamedMetadata("llvm.dependent-libraries")) {
+      for (MDNode *MDOptions : N->operands()) {
+        const auto OperandStr =
+            cast<MDString>(cast<MDNode>(MDOptions)->getOperand(0))->getString();
+        storage::Str Specifier;
+        setStr(Specifier, OperandStr);
+        DependentLibraries.emplace_back(Specifier);
+      }
+    }
+  }
+
   for (ModuleSymbolTable::Symbol Msym : Msymtab.symbols())
     if (Error Err = addSymbol(Msymtab, Used, Msym))
       return Err;
@@ -312,7 +328,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
   writeRange(Hdr.Comdats, Comdats);
   writeRange(Hdr.Symbols, Syms);
   writeRange(Hdr.Uncommons, Uncommons);
-
+  writeRange(Hdr.DependentLibraries, DependentLibraries);
   *reinterpret_cast<storage::Header *>(Symtab.data()) = Hdr;
   return Error::success();
 }
index 1ac624fe958f409b4beabd59ba6a65c79d5a4b77..39e59efe00f60e04ea2288f1b2d49feffb47796e 100644 (file)
@@ -455,6 +455,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
   ECase(SHT_LLVM_LINKER_OPTIONS);
   ECase(SHT_LLVM_CALL_GRAPH_PROFILE);
   ECase(SHT_LLVM_ADDRSIG);
+  ECase(SHT_LLVM_DEPENDENT_LIBRARIES);
   ECase(SHT_GNU_ATTRIBUTES);
   ECase(SHT_GNU_HASH);
   ECase(SHT_GNU_verdef);
diff --git a/test/Feature/elf-deplibs.ll b/test/Feature/elf-deplibs.ll
new file mode 100644 (file)
index 0000000..c44740e
--- /dev/null
@@ -0,0 +1,15 @@
+; RUN: llc -mtriple x86_64-elf -filetype asm -o - %s | FileCheck %s
+; REQUIRES: x86-registered-target
+
+!llvm.dependent-libraries = !{!0, !1, !0}
+
+!0 = !{!"foo"}
+!1 = !{!"b a r"}
+
+; CHECK: .section .deplibs,"MS",@llvm_dependent_libraries,1
+; CHECK-NEXT: .ascii  "foo"
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .ascii  "b a r"
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .ascii  "foo"
+; CHECK-NEXT: .byte   0
index d5f0fbe3700d08c1d814ec7b6151b444315918ba..40864a82dd08616f46b21a70100d1ca02e198342 100644 (file)
@@ -9,6 +9,12 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 !0 = !{!"/include:foo"}
 !llvm.linker.options = !{ !0 }
 
+; CHECK: {{^dependent libraries: \"foo\" \"b a r\" \"baz\"$}}
+!1 = !{!"foo"}
+!2 = !{!"b a r"}
+!3 = !{!"baz"}
+!llvm.dependent-libraries = !{!1, !2, !3}
+
 @g1 = global i32 0
 
 ; CHECK-NOT: fallback g1
index d31909f5f42382d482b5547bcc3a036a5e832f63..7c9bb7915d1af196751aa893ee6928651aff02db 100644 (file)
@@ -293,3 +293,16 @@ bar:
 // CHECK-NEXT:   ]
 // CHECK: }
 
+// Test SHT_LLVM_DEPENDENT_LIBRARIES
+
+.section .deplibs,"MS",@llvm_dependent_libraries,1
+// ASM: .section .deplibs,"MS",@llvm_dependent_libraries,1
+
+// CHECK: Section {
+// CHECK:   Name: .deplibs
+// CHECK-NEXT:   Type: SHT_LLVM_DEPENDENT_LIBRARIES
+// CHECK-NEXT:   Flags [
+// CHECK-NEXT:       SHF_MERGE
+// CHECK-NEXT:       SHF_STRINGS
+// CHECK-NEXT:   ]
+// CHECK: }
index 78e474df9a50c9a95512311dd81cd6f453df7098..1b9915a2b745ef03adc8c501a7824192b5ac132c 100644 (file)
@@ -9,16 +9,17 @@
 
 ; BCA:      <SYMTAB_BLOCK
 ; Version stored at offset 0.
-; BCA-NEXT:   <BLOB abbrevid=4/> blob data = '\x01\x00\x00\x00\x06\x00\x00\x00\x08\x00\x00\x00D\x00\x00\x00\x01\x00\x00\x00P\x00\x00\x00\x00\x00\x00\x00P\x00\x00\x00\x02\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x0E\x00\x00\x00\x18\x00\x00\x00&\x00\x00\x00\x0B\x00\x00\x001\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x00$\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x08$\x00\x00'
+; BCA-NEXT:   <BLOB abbrevid=4/> blob data = '\x02\x00\x00\x00\x06\x00\x00\x00\x08\x00\x00\x00L\x00\x00\x00\x01\x00\x00\x00X\x00\x00\x00\x00\x00\x00\x00X\x00\x00\x00\x02\x00\x00\x00\x88\x00\x00\x00\x00\x00\x00\x00\x0E\x00\x00\x00\x18\x00\x00\x00&\x00\x00\x00\x0B\x00\x00\x001\x00\x00\x00\x00\x00\x00\x00\x88\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x00$\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x08$\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00'
 ; BCA-NEXT: </SYMTAB_BLOCK>
 ; BCA-NEXT: <STRTAB_BLOCK
 ; BCA-NEXT:   <BLOB abbrevid=4/> blob data = 'foobarproducerx86_64-unknown-linux-gnuirsymtab.ll'
 ; BCA-NEXT: </STRTAB_BLOCK>
 
-; SYMTAB:      version: 1
+; SYMTAB:      version: 2
 ; SYMTAB-NEXT: producer: producer
 ; SYMTAB-NEXT: target triple: x86_64-unknown-linux-gnu
 ; SYMTAB-NEXT: source filename: irsymtab.ll
+; SYMTAB-NEXT: {{^dependent libraries: \"foo\" \"bar\"$}}
 ; SYMTAB-NEXT: D------X foo
 ; SYMTAB-NEXT: DU-----X bar
 
@@ -31,3 +32,8 @@ define void @foo() {
 }
 
 declare void @bar()
+
+!llvm.dependent-libraries = !{!0, !1}
+
+!0 = !{!"foo"}
+!1 = !{!"bar"}
index df51921396abce6a9d343d4cdb8d7083d920ba1d..72d80f64a96f141bb335d7bce6550c9dc17c13b5 100644 (file)
@@ -360,6 +360,13 @@ static int dumpSymtab(int argc, char **argv) {
     if (TT.isOSBinFormatCOFF())
       outs() << "linker opts: " << Input->getCOFFLinkerOpts() << '\n';
 
+    if (TT.isOSBinFormatELF()) {
+      outs() << "dependent libraries:";
+      for (auto L : Input->getDependentLibraries())
+        outs() << " \"" << L << "\"";
+      outs() << '\n';
+    }
+
     std::vector<StringRef> ComdatTable = Input->getComdatTable();
     for (const InputFile::Symbol &Sym : Input->symbols()) {
       switch (Sym.getVisibility()) {
index ba6622686b9fdca2e36fce6dde026c7c29d10cc1..755798797628a7e150ebb10f2f5a91d7a6979d50 100644 (file)
@@ -2857,6 +2857,8 @@ static std::string getSectionTypeString(unsigned Arch, unsigned Type) {
     return "LLVM_CALL_GRAPH_PROFILE";
   case SHT_LLVM_ADDRSIG:
     return "LLVM_ADDRSIG";
+  case SHT_LLVM_DEPENDENT_LIBRARIES:
+    return "LLVM_DEPENDENT_LIBRARIES";
   // FIXME: Parse processor specific GNU attributes
   case SHT_GNU_ATTRIBUTES:
     return "ATTRIBUTES";
index 379b5b897141af094f113e0e43e917119cd88560..01dc141ffd0190031442894bd18510e226c1f6cd 100644 (file)
@@ -325,6 +325,10 @@ const char* lto_module_get_linkeropts(lto_module_t mod) {
   return unwrap(mod)->getLinkerOpts().data();
 }
 
+const char* lto_module_get_dependent_libraries(lto_module_t mod) {
+    return unwrap(mod)->getDependentLibraries().data();
+}
+
 void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg,
                                         lto_diagnostic_handler_t diag_handler,
                                         void *ctxt) {