[lld] 9e08e92 - [ELF] Allow STV_PROTECTED shared definition to set exportDynamic

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 5 01:11:22 PST 2022


Author: Fangrui Song
Date: 2022-02-05T01:10:43-08:00
New Revision: 9e08e9298059651e4f42eb608c3de9d4ad8004b2

URL: https://github.com/llvm/llvm-project/commit/9e08e9298059651e4f42eb608c3de9d4ad8004b2
DIFF: https://github.com/llvm/llvm-project/commit/9e08e9298059651e4f42eb608c3de9d4ad8004b2.diff

LOG: [ELF] Allow STV_PROTECTED shared definition to set exportDynamic

A STV_PROTECTED shared definition does not set exportDynamic of a defined
symbol. This is on the basis that a protected definition cannot be preempted so
the export is unnecessary. However, the condition is imperfect because we don't
know whether the shared object was built with a symbolic option. Since dropping
the condition simplifies code and matches GNU ld, let's do it.

Added: 
    

Modified: 
    lld/ELF/LTO.cpp
    lld/ELF/Symbols.h
    lld/test/ELF/lto/unnamed-addr-lib.ll

Removed: 
    


################################################################################
diff  --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 88fcd8baf9c91..5c10df489d916 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -254,7 +254,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
     // Identify symbols exported dynamically, and that therefore could be
     // referenced by a shared library not visible to the linker.
     r.ExportDynamic = sym->computeBinding() != STB_LOCAL &&
-                      (sym->isExportDynamic(sym->kind(), sym->visibility) ||
+                      (sym->isExportDynamic(sym->kind()) ||
                        sym->exportDynamic || sym->inDynamicList);
     const auto *dr = dyn_cast<Defined>(sym);
     r.FinalDefinitionInLinkageUnit =

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index cd5d4b280e793..22d57e54d2f0e 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -228,10 +228,8 @@ class Symbol {
   // non-lazy object causes a runtime error.
   void extract() const;
 
-  static bool isExportDynamic(Kind k, uint8_t visibility) {
-    if (k == SharedKind)
-      return visibility == llvm::ELF::STV_DEFAULT;
-    return config->shared || config->exportDynamic;
+  static bool isExportDynamic(Kind k) {
+    return k == SharedKind || config->shared || config->exportDynamic;
   }
 
 private:
@@ -252,7 +250,7 @@ class Symbol {
         binding(binding), type(type), stOther(stOther), symbolKind(k),
         visibility(stOther & 3),
         isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
-        exportDynamic(isExportDynamic(k, visibility)), inDynamicList(false),
+        exportDynamic(isExportDynamic(k)), inDynamicList(false),
         canInline(false), referenced(false), traced(false),
         hasVersionSuffix(false), isInIplt(false), gotInIgot(false),
         isPreemptible(false), used(!config->gcSections), folded(false),

diff  --git a/lld/test/ELF/lto/unnamed-addr-lib.ll b/lld/test/ELF/lto/unnamed-addr-lib.ll
index 7b9dd530c23fc..a6f9eba268044 100644
--- a/lld/test/ELF/lto/unnamed-addr-lib.ll
+++ b/lld/test/ELF/lto/unnamed-addr-lib.ll
@@ -5,13 +5,7 @@
 ; RUN: ld.lld %t.o %t2.so -o %t.so -save-temps -shared
 ; RUN: llvm-dis %t.so.0.2.internalize.bc -o - | FileCheck %s
 
-; This documents a small limitation of lld's internalization logic. We decide
-; that bar should be in the symbol table because if it is it will preempt the
-; one in the shared library.
-; We could add one extra bit for ODR so that we know that preemption is not
-; necessary, but that is probably not worth it.
-
-; CHECK: @foo = internal unnamed_addr constant i8 42
+; CHECK: @foo = weak_odr unnamed_addr constant i8 42
 ; CHECK: @bar = weak_odr unnamed_addr constant i8 42
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"


        


More information about the llvm-commits mailing list