[PATCH] D101716: [lld][WebAssembly] Fix crash with `-pie` without `--allow-undefined`

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 3 18:05:40 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG808fcddae406: [lld][WebAssembly] Fix crash with `-pie` without `--allow-undefined` (authored by sbc100).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101716/new/

https://reviews.llvm.org/D101716

Files:
  lld/test/wasm/pie.ll
  lld/wasm/Relocations.cpp
  lld/wasm/Writer.cpp


Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -560,7 +560,7 @@
   if (isa<DataSymbol>(sym))
     return false;
 
-  if (config->relocatable ||
+  if ((config->isPic || config->relocatable) ||
       config->unresolvedSymbols == UnresolvedPolicy::ImportFuncs)
     return true;
   if (config->allowUndefinedSymbols.count(sym->getName()) != 0)
Index: lld/wasm/Relocations.cpp
===================================================================
--- lld/wasm/Relocations.cpp
+++ lld/wasm/Relocations.cpp
@@ -150,10 +150,9 @@
           addGOTEntry(sym);
         break;
       }
-    } else {
+    } else if (sym->isUndefined() && !config->relocatable && !sym->isWeak()) {
       // Report undefined symbols
-      if (sym->isUndefined() && !config->relocatable && !sym->isWeak())
-        reportUndefined(sym);
+      reportUndefined(sym);
     }
   }
 }
Index: lld/test/wasm/pie.ll
===================================================================
--- lld/test/wasm/pie.ll
+++ lld/test/wasm/pie.ll
@@ -1,5 +1,5 @@
 ; RUN: llc -relocation-model=pic -mattr=+mutable-globals -filetype=obj %s -o %t.o
-; RUN: wasm-ld --no-gc-sections --allow-undefined --experimental-pic -pie -o %t.wasm %t.o
+; RUN: wasm-ld --no-gc-sections --experimental-pic -pie -o %t.wasm %t.o
 
 target triple = "wasm32-unknown-emscripten"
 
@@ -26,9 +26,12 @@
 }
 
 define void @_start() {
+  call void @external_func()
   ret void
 }
 
+declare void @external_func()
+
 ;      CHECK: Sections:
 ; CHECK-NEXT:   - Type:            CUSTOM
 ; CHECK-NEXT:     Name:            dylink
@@ -88,27 +91,29 @@
 ; RUN: obj2yaml %t.shmem.wasm | FileCheck %s --check-prefix=SHMEM
 
 ; SHMEM:         - Type:            CODE
-; SHMEM:           - Index:           5
+; SHMEM:           - Index:           6
 ; SHMEM-NEXT:        Locals:          []
-; SHMEM-NEXT:        Body:            100210040B
+; SHMEM-NEXT:        Body:            100310050B
 
 ; SHMEM:         FunctionNames:
 ; SHMEM-NEXT:      - Index:           0
-; SHMEM-NEXT:        Name:            __wasm_call_ctors
+; SHMEM-NEXT:        Name:            external_func
 ; SHMEM-NEXT:      - Index:           1
-; SHMEM-NEXT:        Name:            __wasm_init_tls
+; SHMEM-NEXT:        Name:            __wasm_call_ctors
 ; SHMEM-NEXT:      - Index:           2
-; SHMEM-NEXT:        Name:            __wasm_init_memory
+; SHMEM-NEXT:        Name:            __wasm_init_tls
 ; SHMEM-NEXT:      - Index:           3
-; SHMEM-NEXT:        Name:            __wasm_apply_data_relocs
+; SHMEM-NEXT:        Name:            __wasm_init_memory
 ; SHMEM-NEXT:      - Index:           4
-; SHMEM-NEXT:        Name:            __wasm_apply_global_relocs
+; SHMEM-NEXT:        Name:            __wasm_apply_data_relocs
 ; SHMEM-NEXT:      - Index:           5
-; SHMEM-NEXT:        Name:            __wasm_start
+; SHMEM-NEXT:        Name:            __wasm_apply_global_relocs
 ; SHMEM-NEXT:      - Index:           6
-; SHMEM-NEXT:        Name:            foo
+; SHMEM-NEXT:        Name:            __wasm_start
 ; SHMEM-NEXT:      - Index:           7
-; SHMEM-NEXT:        Name:            get_data_address
+; SHMEM-NEXT:        Name:            foo
 ; SHMEM-NEXT:      - Index:           8
+; SHMEM-NEXT:        Name:            get_data_address
+; SHMEM-NEXT:      - Index:           9
 ; SHMEM-NEXT:        Name:            _start
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101716.342613.patch
Type: text/x-patch
Size: 3453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/52df4b1e/attachment.bin>


More information about the llvm-commits mailing list