]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] MC: Fix references to undefined externals in data section
authorSam Clegg <sbc@chromium.org>
Fri, 2 Jun 2017 01:05:24 +0000 (01:05 +0000)
committerSam Clegg <sbc@chromium.org>
Fri, 2 Jun 2017 01:05:24 +0000 (01:05 +0000)
Undefined externals don't need to have a size or an offset.
This was broken by r303915.  Added a test for this case.

This fixes the "Compile LLVM Torture (o)" step on the wasm
waterfall.

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

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

lib/MC/WasmObjectWriter.cpp
lib/Target/WebAssembly/known_gcc_test_failures.txt
test/MC/WebAssembly/external-data.ll [new file with mode: 0644]

index 8c3df36cfb488d62971b0b5815ea02b791f8b8b1..616fe0f2e629627d904c42881352562aa272e876 100644 (file)
@@ -730,16 +730,21 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
       if (IsAddressTaken.count(&WS))
         TableElems.push_back(Index);
     } else {
-      if (WS.getOffset() != 0)
-        report_fatal_error("data sections must contain one variable each");
-      if (!WS.getSize())
-        report_fatal_error("data symbols must have a size set with .size");
-
-      int64_t Size = 0;
-      if (!WS.getSize()->evaluateAsAbsolute(Size, Layout))
-        report_fatal_error(".size expression must be evaluatable");
+      if (WS.isTemporary() && !WS.getSize())
+        continue;
 
       if (WS.isDefined(false)) {
+        if (WS.getOffset() != 0)
+          report_fatal_error("data sections must contain one variable each: " +
+                             WS.getName());
+        if (!WS.getSize())
+          report_fatal_error("data symbols must have a size set with .size: " +
+                             WS.getName());
+
+        int64_t Size = 0;
+        if (!WS.getSize()->evaluateAsAbsolute(Size, Layout))
+          report_fatal_error(".size expression must be evaluatable");
+
         MCSectionWasm &DataSection =
             static_cast<MCSectionWasm &>(WS.getSection());
 
index 54619589c3418d1fbfc7980020c18ca3629c7b05..35a67134775a646df3159b2267b047a1b41bcc3e 100644 (file)
@@ -88,6 +88,3 @@ pr45695.c wasm-o
 pr49279.c wasm-o
 pr49390.c wasm-o
 pr52286.c wasm-o
-
-# fatal error: error in backend: data symbols must have a size set with .size
-921110-1.c wasm-o
diff --git a/test/MC/WebAssembly/external-data.ll b/test/MC/WebAssembly/external-data.ll
new file mode 100644 (file)
index 0000000..91e05b3
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s
+; Verify relocations are correctly generated for addresses of externals
+; in the data section.
+
+declare i32 @f1(...)
+
+@foo = global i64 7, align 4
+@far = local_unnamed_addr global i32 (...)* @f1, align 4
+
+; CHECK:   - Type:            DATA
+; CHECK:     Relocations:
+; CHECK:       - Type:            R_WEBASSEMBLY_GLOBAL_ADDR_I32
+; CHECK:         Index:           0
+; CHECK:         Offset:          0x0000000E
+; CHECK:     Segments:
+; CHECK:       - Index:           0
+; CHECK:         Offset:
+; CHECK:           Opcode:          I32_CONST
+; CHECK:           Value:           0
+; CHECK:         Content:         0700000000000000FFFFFFFF
+