[PATCH] D49446: [WebAssembly] Move .debug_line section address of dead function outside section range

Yury Delendik via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 18 11:30:59 PDT 2018


yurydelendik updated this revision to Diff 156118.
yurydelendik added a comment.

Fix comment


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D49446

Files:
  test/wasm/debug-removed-fn.ll
  wasm/InputChunks.h
  wasm/InputFiles.cpp


Index: wasm/InputFiles.cpp
===================================================================
--- wasm/InputFiles.cpp
+++ wasm/InputFiles.cpp
@@ -20,6 +20,11 @@
 
 #define DEBUG_TYPE "lld"
 
+// The relocatable values for R_WEBASSEMBLY_FUNCTION_OFFSET_I32 will point
+// outside code section code. This start offset is selected based on max code
+// section size (1024 * 1024 * 1024) and max function body length (76545321).
+#define DEAD_FUNCTION_OFFSET 0xFDEAD000
+
 using namespace lld;
 using namespace lld::wasm;
 
@@ -137,6 +142,8 @@
     return getGlobalSymbol(Reloc.Index)->getGlobalIndex();
   case R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
     if (auto *Sym = dyn_cast<DefinedFunction>(getFunctionSymbol(Reloc.Index))) {
+      if (Sym->Function->OutputOffset == InputFunction::UNKNOWN_OUTPUT_OFFSET)
+        return DEAD_FUNCTION_OFFSET;
       return Sym->Function->OutputOffset +
              Sym->Function->getFunctionCodeOffset() + Reloc.Addend;
     }
Index: wasm/InputChunks.h
===================================================================
--- wasm/InputChunks.h
+++ wasm/InputChunks.h
@@ -44,6 +44,8 @@
 
 class InputChunk {
 public:
+  static const int32_t UNKNOWN_OUTPUT_OFFSET = 0;
+
   enum Kind { DataSegment, Function, SyntheticFunction, Section };
 
   Kind kind() const { return SectionKind; }
@@ -65,7 +67,7 @@
   void writeRelocations(llvm::raw_ostream &OS) const;
 
   ObjFile *File;
-  int32_t OutputOffset = 0;
+  int32_t OutputOffset = UNKNOWN_OUTPUT_OFFSET;
 
   // Signals that the section is part of the output.  The garbage collector,
   // and COMDAT handling can set a sections' Live bit.
Index: test/wasm/debug-removed-fn.ll
===================================================================
--- /dev/null
+++ test/wasm/debug-removed-fn.ll
@@ -0,0 +1,44 @@
+; RUN: llc -filetype=obj < %s -o %t.o
+; RUN: wasm-ld %t.o --no-entry --export=foo -o %t.wasm
+; RUN: llvm-dwarfdump -debug-line %t.wasm | FileCheck %s
+
+; CHECK: Address
+; CHECK: 0x0000000000000
+; CHECK: 0x00000000fdead
+
+; ModuleID = 't.bc'
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+; Function Attrs: noinline nounwind optnone
+define hidden i32 @foo() #0 !dbg !7 {
+entry:
+  ret i32 42, !dbg !11
+}
+
+; Function Attrs: noinline nounwind optnone
+define hidden i32 @bar() #0 !dbg !12 {
+entry:
+  ret i32 6, !dbg !13
+}
+
+attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 337293)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "t.c", directory: "/d/y")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 7.0.0 (trunk 337293)"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocation(line: 2, column: 3, scope: !7)
+!12 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, isLocal: false, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !0, retainedNodes: !2)
+!13 = !DILocation(line: 6, column: 3, scope: !12)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49446.156118.patch
Type: text/x-patch
Size: 3901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180718/5b531314/attachment.bin>


More information about the llvm-commits mailing list