[lld] d2a0ef9 - [lld][WebAssembly] Don't force the export symbols assiged internal/dummy GOT entries

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 15 17:30:27 PST 2022


Author: Sam Clegg
Date: 2022-02-15T17:29:45-08:00
New Revision: d2a0ef984470536cf3fbdef1ee66e6fe113501b4

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

LOG: [lld][WebAssembly] Don't force the export symbols assiged internal/dummy GOT entries

Symbols with regular GOT entries do need to be exported, but those that
are internalized (and have dymmy/internal GOT entries) need not be
exported.

This happens to fix the failures on the emscripten waterfall where extra
symbols were being exported by the linker (and then later removed by
wasm-opt).

Differential Revision: https://reviews.llvm.org/D119902

Added: 
    

Modified: 
    lld/test/wasm/tls-non-shared-memory.s
    lld/wasm/Symbols.cpp
    lld/wasm/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/tls-non-shared-memory.s b/lld/test/wasm/tls-non-shared-memory.s
index 0468129bab5b1..2c010049e1939 100644
--- a/lld/test/wasm/tls-non-shared-memory.s
+++ b/lld/test/wasm/tls-non-shared-memory.s
@@ -46,10 +46,10 @@ tls1:
 # RUN: obj2yaml %t.wasm | FileCheck %s
 
 # RUN: wasm-ld --experimental-pic -shared -o %t.so %t.o
-# RUN: obj2yaml %t.so | FileCheck %s --check-prefix=PIC
+# RUN: obj2yaml %t.so | FileCheck %s --check-prefixes=SHARED,PIC
 
 # RUN: wasm-ld --experimental-pic --no-gc-sections --no-entry -pie -o %t-pie.wasm %t.o
-# RUN: obj2yaml %t.so | FileCheck %s --check-prefix=PIC
+# RUN: obj2yaml %t-pie.wasm | FileCheck %s --check-prefixes=PIE,PIC
 
 #      CHECK:   - Type:            GLOBAL
 # __stack_pointer
@@ -98,17 +98,33 @@ tls1:
 # In PIC mode we expect TLS data and non-TLS data to be merged into
 # a single segment which is initialized via the  __memory_base import
 
-#      PIC:  - Type:            IMPORT
-# PIC-NEXT:    Imports:
-# PIC-NEXT:      - Module:          env
-# PIC-NEXT:        Field:           memory
-# PIC-NEXT:        Kind:            MEMORY
-# PIC-NEXT:        Memory:
-# PIC-NEXT:          Minimum:         0x1
-# PIC-NEXT:      - Module:          env
-# PIC-NEXT:        Field:           __memory_base
-# PIC-NEXT:        Kind:            GLOBAL
-# PIC-NEXT:        GlobalType:      I32
+#      SHARED:  - Type:            IMPORT
+# SHARED-NEXT:    Imports:
+# SHARED-NEXT:      - Module:          env
+# SHARED-NEXT:        Field:           memory
+# SHARED-NEXT:        Kind:            MEMORY
+# SHARED-NEXT:        Memory:
+# SHARED-NEXT:          Minimum:         0x1
+# SHARED-NEXT:      - Module:          env
+# SHARED-NEXT:        Field:           __memory_base
+# SHARED-NEXT:        Kind:            GLOBAL
+# SHARED-NEXT:        GlobalType:      I32
+
+# In SHARED mode we export the address of all data symbols.
+#      SHARED:   - Type:            EXPORT
+# SHARED-NEXT:     Exports:
+#      SHARED:     - Name:            tls1
+# SHARED-NEXT:       Kind:            GLOBAL
+#      SHARED:     - Name:            no_tls
+# SHARED-NEXT:       Kind:            GLOBAL
+
+# In PIE mode we don't export data address by default.
+#      PIE:   - Type:            EXPORT
+# PIE-NEXT:     Exports:
+# PIE-NEXT:       - Name:            memory
+# PIE-NEXT:         Kind:            MEMORY
+# PIE-NEXT:         Index:           0
+# PIE-NEXT:   - Type:
 
 # .tdata and .data are combined into single segment in PIC mode.
 #      PIC:  - Type:            DATA
@@ -117,6 +133,6 @@ tls1:
 # PIC-NEXT:        InitFlags:       0
 # PIC-NEXT:        Offset:
 # PIC-NEXT:          Opcode:          GLOBAL_GET
-# PIC-NEXT:          Index:           0
+# PIC-NEXT:          Index:           {{\d*}}
 # PIC-NEXT:        Content:         2B0000002A000000
 # PIC-NEXT:  - Type:            CUSTOM

diff  --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index 5e6dcf8ca7919..2ad21c8947f36 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -190,11 +190,6 @@ void Symbol::setOutputSymbolIndex(uint32_t index) {
 void Symbol::setGOTIndex(uint32_t index) {
   LLVM_DEBUG(dbgs() << "setGOTIndex " << name << " -> " << index << "\n");
   assert(gotIndex == INVALID_INDEX);
-  if (config->isPic) {
-    // Any symbol that is assigned a GOT entry must be exported otherwise the
-    // dynamic linker won't be able create the entry that contains it.
-    forceExport = true;
-  }
   gotIndex = index;
 }
 

diff  --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 7fc5c32402d3d..2142b0261ae40 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -167,6 +167,12 @@ void ImportSection::addGOTEntry(Symbol *sym) {
     return;
   LLVM_DEBUG(dbgs() << "addGOTEntry: " << toString(*sym) << "\n");
   sym->setGOTIndex(numImportedGlobals++);
+  if (config->isPic) {
+    // Any symbol that is assigned an normal GOT entry must be exported
+    // otherwise the dynamic linker won't be able create the entry that contains
+    // it.
+    sym->forceExport = true;
+  }
   gotSymbols.push_back(sym);
 }
 


        


More information about the llvm-commits mailing list