Commit a33b689f2c

Andrew Kelley <superjoe30@gmail.com>
2018-02-23 19:04:47
update embedded LLD to 6.0.0rc3
1 parent 9cfd7de
Changed files (9)
deps/lld/COFF/PDB.cpp
@@ -96,10 +96,11 @@ public:
   /// If the object does not use a type server PDB (compiled with /Z7), we merge
   /// all the type and item records from the .debug$S stream and fill in the
   /// caller-provided ObjectIndexMap.
-  const CVIndexMap &mergeDebugT(ObjFile *File, CVIndexMap &ObjectIndexMap);
+  Expected<const CVIndexMap&> mergeDebugT(ObjFile *File,
+                                          CVIndexMap &ObjectIndexMap);
 
-  const CVIndexMap &maybeMergeTypeServerPDB(ObjFile *File,
-                                            TypeServer2Record &TS);
+  Expected<const CVIndexMap&> maybeMergeTypeServerPDB(ObjFile *File,
+                                                      TypeServer2Record &TS);
 
   /// Add the section map and section contributions to the PDB.
   void addSections(ArrayRef<OutputSection *> OutputSections,
@@ -140,6 +141,10 @@ private:
 
   /// Type index mappings of type server PDBs that we've loaded so far.
   std::map<GUID, CVIndexMap> TypeServerIndexMappings;
+
+  /// List of TypeServer PDBs which cannot be loaded.
+  /// Cached to prevent repeated load attempts.
+  std::set<GUID> MissingTypeServerPDBs;
 };
 }
 
@@ -230,8 +235,8 @@ maybeReadTypeServerRecord(CVTypeArray &Types) {
   return std::move(TS);
 }
 
-const CVIndexMap &PDBLinker::mergeDebugT(ObjFile *File,
-                                         CVIndexMap &ObjectIndexMap) {
+Expected<const CVIndexMap&> PDBLinker::mergeDebugT(ObjFile *File,
+                                                   CVIndexMap &ObjectIndexMap) {
   ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T");
   if (Data.empty())
     return ObjectIndexMap;
@@ -304,11 +309,19 @@ tryToLoadPDB(const GUID &GuidFromObj, StringRef TSPath) {
   return std::move(NS);
 }
 
-const CVIndexMap &PDBLinker::maybeMergeTypeServerPDB(ObjFile *File,
-                                                     TypeServer2Record &TS) {
-  // First, check if we already loaded a PDB with this GUID. Return the type
+Expected<const CVIndexMap&> PDBLinker::maybeMergeTypeServerPDB(ObjFile *File,
+                                                               TypeServer2Record &TS) {
+  const GUID& TSId = TS.getGuid();
+  StringRef TSPath = TS.getName();
+
+  // First, check if the PDB has previously failed to load.
+  if (MissingTypeServerPDBs.count(TSId))
+    return make_error<pdb::GenericError>(
+      pdb::generic_error_code::type_server_not_found, TSPath);
+
+  // Second, check if we already loaded a PDB with this GUID. Return the type
   // index mapping if we have it.
-  auto Insertion = TypeServerIndexMappings.insert({TS.getGuid(), CVIndexMap()});
+  auto Insertion = TypeServerIndexMappings.insert({TSId, CVIndexMap()});
   CVIndexMap &IndexMap = Insertion.first->second;
   if (!Insertion.second)
     return IndexMap;
@@ -319,18 +332,21 @@ const CVIndexMap &PDBLinker::maybeMergeTypeServerPDB(ObjFile *File,
   // Check for a PDB at:
   // 1. The given file path
   // 2. Next to the object file or archive file
-  auto ExpectedSession = tryToLoadPDB(TS.getGuid(), TS.getName());
+  auto ExpectedSession = tryToLoadPDB(TSId, TSPath);
   if (!ExpectedSession) {
     consumeError(ExpectedSession.takeError());
     StringRef LocalPath =
         !File->ParentName.empty() ? File->ParentName : File->getName();
     SmallString<128> Path = sys::path::parent_path(LocalPath);
     sys::path::append(
-        Path, sys::path::filename(TS.getName(), sys::path::Style::windows));
-    ExpectedSession = tryToLoadPDB(TS.getGuid(), Path);
+        Path, sys::path::filename(TSPath, sys::path::Style::windows));
+    ExpectedSession = tryToLoadPDB(TSId, Path);
+  }
+  if (auto E = ExpectedSession.takeError()) {
+    TypeServerIndexMappings.erase(TSId);
+    MissingTypeServerPDBs.emplace(TSId);
+    return std::move(E);
   }
-  if (auto E = ExpectedSession.takeError())
-    fatal("Type server PDB was not found: " + toString(std::move(E)));
 
   auto ExpectedTpi = (*ExpectedSession)->getPDBFile().getPDBTpiStream();
   if (auto E = ExpectedTpi.takeError())
@@ -707,7 +723,16 @@ void PDBLinker::addObjFile(ObjFile *File) {
   // the PDB first, so that we can get the map from object file type and item
   // indices to PDB type and item indices.
   CVIndexMap ObjectIndexMap;
-  const CVIndexMap &IndexMap = mergeDebugT(File, ObjectIndexMap);
+  auto IndexMapResult = mergeDebugT(File, ObjectIndexMap);
+
+  // If the .debug$T sections fail to merge, assume there is no debug info.
+  if (!IndexMapResult) {
+    warn("Type server PDB for " + Name + " is invalid, ignoring debug info. " +
+         toString(IndexMapResult.takeError()));
+    return;
+  }
+
+  const CVIndexMap &IndexMap = *IndexMapResult;
 
   // Now do all live .debug$S sections.
   for (SectionChunk *DebugChunk : File->getDebugChunks()) {
deps/lld/docs/ReleaseNotes.rst
@@ -5,17 +5,12 @@ LLD 6.0.0 Release Notes
 .. contents::
     :local:
 
-.. warning::
-   These are in-progress notes for the upcoming LLVM 6.0.0 release.
-   Release notes for previous releases can be found on
-   `the Download Page <http://releases.llvm.org/download.html>`_.
-
 Introduction
 ============
 
-This document contains the release notes for the LLD linker, release 6.0.0.
-Here we describe the status of LLD, including major improvements
-from the previous release. All LLD releases may be downloaded
+This document contains the release notes for the lld linker, release 6.0.0.
+Here we describe the status of lld, including major improvements
+from the previous release. All lld releases may be downloaded
 from the `LLVM releases web site <http://llvm.org/releases/>`_.
 
 Non-comprehensive list of changes in this release
@@ -24,20 +19,81 @@ Non-comprehensive list of changes in this release
 ELF Improvements
 ----------------
 
-* Item 1.
+* A lot of bugs and compatibility issues have been identified and fixed as a
+  result of people using lld 5.0 as a standard system linker. In particular,
+  linker script and version script support has significantly improved that
+  it should be able to handle almost all scripts.
+
+* A mitigation for Spectre v2 has been implemented. If you pass ``-z
+  retpolineplt``, lld uses RET instruction instead of JMP instruction in PLT.
+  The option is available for x86 and x86-64.
+
+* Identical Code Folding (ICF) now de-duplicates .eh_frame entries, so lld now
+  generates slightly smaller outputs than before when you pass ``--icf=all``.
+
+* Analysis for ``--as-needed`` is now done after garbage collection. If garbage
+  collector eliminates all sections that use some library, that library is
+  eliminated from DT_NEEDED tags. Previously, the analysis ran before garbage
+  collection.
+
+* Size of code segment is now always rounded up to page size to make sure that
+  unused bytes at end of code segment is filled with trap instructions (such
+  as INT3) instead of zeros.
+
+* lld is now able to generate Android-style compact dynamic relocation table.
+  You can turn on the feature by passing ``--pack-dyn-relocs=android``.
+
+* Debug information is used in more cases when reporting errors.
+
+* ``--gdb-index`` gets faster than before.
+
+* String merging is now multi-threaded, which makes ``-O2`` faster.
+
+* ``--hash-style=both`` is now default instead of ``--hash-style=sysv`` to
+  match the behavior of recent versions of GNU linkers.
+
+* ARM PLT entries automatically use short or long variants.
+
+* lld can now identify and patch a code sequence that triggers AArch64 errata 843419.
+  Add ``--fix-cortex-a53-843419`` to enable the feature.
+
+* lld can now generate thunks for out of range thunks.
+
+* MIPS port now generates all output dynamic relocations using Elf_Rel format only.
+
+* Added handling of the R_MIPS_26 relocation in case of N32/N64 ABIs and
+  generating proper PLT entries.
+
+* The following options have been added: ``--icf=none`` ``-z muldefs``
+  ``--plugin-opt`` ``--no-eh-frame-hdr`` ``--no-gdb-index``
+  ``--orphan-handling={place,discard,warn,error}``
+  ``--pack-dyn-relocs={none,android}`` ``--no-omagic``
+  ``--no-print-gc-sections`` ``--ignore-function-address-equality`` ``-z
+  retpolineplt`` ``--print-icf-sections`` ``--no-pie``
 
 COFF Improvements
 -----------------
 
 * A GNU ld style frontend for the COFF linker has been added for MinGW.
   In MinGW environments, the linker is invoked with GNU ld style parameters;
-  which LLD previously only supported when used as an ELF linker. When
+  which lld previously only supported when used as an ELF linker. When
   a PE/COFF target is chosen, those parameters are rewritten into the
   lld-link style parameters and the COFF linker is invoked instead.
 
 * Initial support for the ARM64 architecture has been added.
 
-MachO Improvements
-------------------
+* New ``--version`` flag.
+
+* Significantly improved support for writing PDB Files.
+
+* New ``--rsp-quoting`` flag, like ``clang-cl``.
+
+* ``/manifestuac:no`` no longer incorrectly disables ``/manifestdependency:``.
+
+* Only write ``.manifest`` files if ``/manifest`` is passed.
+
+WebAssembly Improvements
+------------------------
 
-* Item 1.
+* Initial version of WebAssembly support has landed. You can invoke the
+  WebAssembly linker by ``wasm-ld``.
deps/lld/ELF/Driver.cpp
@@ -638,7 +638,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
   Config->Optimize = args::getInteger(Args, OPT_O, 1);
   Config->OrphanHandling = getOrphanHandling(Args);
   Config->OutputFile = Args.getLastArgValue(OPT_o);
-  Config->Pie = Args.hasFlag(OPT_pie, OPT_no_pie, false);
+  Config->Pie = Args.hasFlag(OPT_pie, OPT_nopie, false);
   Config->PrintGcSections =
       Args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);
   Config->Rpath = getRpath(Args);
@@ -1061,7 +1061,12 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
     addReservedSymbols();
 
   // Apply version scripts.
-  Symtab->scanVersionScript();
+  //
+  // For a relocatable output, version scripts don't make sense, and
+  // parsing a symbol version string (e.g. dropping "@ver1" from a symbol
+  // name "foo@ver1") rather do harm, so we don't call this if -r is given.
+  if (!Config->Relocatable)
+    Symtab->scanVersionScript();
 
   // Create wrapped symbols for -wrap option.
   for (auto *Arg : Args.filtered(OPT_wrap))
deps/lld/ELF/Options.td
@@ -202,8 +202,6 @@ def no_gnu_unique: F<"no-gnu-unique">,
 def no_merge_exidx_entries: F<"no-merge-exidx-entries">,
   HelpText<"Disable merging .ARM.exidx entries">;
 
-def no_pie: F<"no-pie">, HelpText<"Do not create a position independent executable">;
-
 def no_threads: F<"no-threads">,
   HelpText<"Do not run the linker multi-threaded">;
 
@@ -213,6 +211,8 @@ def no_whole_archive: F<"no-whole-archive">,
 def noinhibit_exec: F<"noinhibit-exec">,
   HelpText<"Retain the executable output file whenever it is still usable">;
 
+def nopie: F<"nopie">, HelpText<"Do not create a position independent executable">;
+
 def no_omagic: Flag<["--"], "no-omagic">, MetaVarName<"<magic>">,
   HelpText<"Do not set the text data sections to be writable">;
 
deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
@@ -621,6 +621,7 @@ void ArchHandler_x86_64::applyFixupFinal(
     // Fall into llvm_unreachable().
     break;
   }
+  llvm_unreachable("invalid x86_64 Reference Kind");
 }
 
 void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,
deps/lld/test/COFF/pdb-type-server-missing.yaml
@@ -1,13 +1,10 @@
 # This is an object compiled with /Zi (see the LF_TYPESERVER2 record) without an
 # adjacent type server PDB. Test that LLD fails gracefully on it.
 
-# FIXME: Ideally we'd do what MSVC does, which is to warn and drop all debug
-# info in the object with the missing PDB.
-
 # RUN: yaml2obj %s -o %t.obj
-# RUN: not lld-link %t.obj -out:%t.exe -debug -pdb:%t.pdb -nodefaultlib -entry:main 2>&1 | FileCheck %s
+# RUN: lld-link %t.obj -out:%t.exe -debug -pdb:%t.pdb -nodefaultlib -entry:main 2>&1 | FileCheck %s
 
-# CHECK: error: Type server PDB was not found
+# CHECK: warning: Type server PDB for {{.*}}.obj is invalid, ignoring debug info.
 
 --- !COFF
 header:
deps/lld/test/ELF/pie.s
@@ -48,7 +48,7 @@
 # CHECK:         Type: PT_DYNAMIC
 
 ## Check -nopie
-# RUN: ld.lld -no-pie %t1.o -o %t2
+# RUN: ld.lld -nopie %t1.o -o %t2
 # RUN: llvm-readobj -file-headers -r %t2 | FileCheck %s --check-prefix=NOPIE
 # NOPIE-NOT: Type: SharedObject
 
deps/lld/test/ELF/relocatable-versioned.s
@@ -0,0 +1,9 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld -o %t2.o -r %t1.o
+# RUN: llvm-nm %t2.o | FileCheck %s
+# CHECK: foo@VERSION
+
+.global "foo@VERSION"
+"foo@VERSION":
+  ret
deps/lld-prebuilt/ELF/Options.inc
@@ -230,8 +230,6 @@ OPTION(prefix_2, "no-merge-exidx-entries", no_merge_exidx_entries, Flag, INVALID
 OPTION(prefix_2, "no-mmap-output-file", no_mmap_output_file, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
 OPTION(prefix_3, "no-omagic", no_omagic, Flag, INVALID, INVALID, nullptr, 0, 0,
        "Do not set the text data sections to be writable", "<magic>", nullptr)
-OPTION(prefix_2, "no-pie", no_pie, Flag, INVALID, INVALID, nullptr, 0, 0,
-       "Do not create a position independent executable", nullptr, nullptr)
 OPTION(prefix_2, "no-print-gc-sections", no_print_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
        "Do not list removed unused sections", nullptr, nullptr)
 OPTION(prefix_2, "no-rosegment", no_rosegment, Flag, INVALID, INVALID, nullptr, 0, 0,
@@ -249,6 +247,8 @@ OPTION(prefix_2, "no-whole-archive", no_whole_archive, Flag, INVALID, INVALID, n
 OPTION(prefix_2, "noinhibit-exec", noinhibit_exec, Flag, INVALID, INVALID, nullptr, 0, 0,
        "Retain the executable output file whenever it is still usable", nullptr, nullptr)
 OPTION(prefix_2, "non_shared", alias_Bstatic_non_shared, Flag, INVALID, Bstatic, nullptr, 0, 0, nullptr, nullptr, nullptr)
+OPTION(prefix_2, "nopie", nopie, Flag, INVALID, INVALID, nullptr, 0, 0,
+       "Do not create a position independent executable", nullptr, nullptr)
 OPTION(prefix_2, "nostdlib", nostdlib, Flag, INVALID, INVALID, nullptr, 0, 0,
        "Only search directories specified on the command line", nullptr, nullptr)
 OPTION(prefix_1, "N", alias_omagic, Flag, INVALID, omagic, nullptr, 0, 0, nullptr, nullptr, nullptr)