This is an archive of the discontinued LLVM Phabricator instance.

COFF: Allow the combined LTO object to define new symbols.
ClosedPublic

Authored by pcc on Jun 8 2015, 5:23 PM.

Details

Summary

The LLVM code generator can sometimes synthesize symbols, such as SSE
constants, that are not visible via the LTOModule interface. Allow such
symbols so long as they have definitions.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 27351.Jun 8 2015, 5:23 PM
pcc retitled this revision from to COFF: Allow the combined LTO object to define new symbols..
pcc updated this object.
pcc edited the test plan for this revision. (Show Details)
pcc added a reviewer: ruiu.
pcc added a subscriber: Unknown Object (MLST).
ruiu edited edge metadata.Jun 8 2015, 6:31 PM

LGTM
2015/06/08 午後5:23 "Peter Collingbourne" <peter@pcc.me.uk>:

Hi ruiu,

The LLVM code generator can sometimes synthesize symbols, such as SSE
constants, that are not visible via the LTOModule interface. Allow such
symbols so long as they have definitions.

http://reviews.llvm.org/D10331

Files:

COFF/SymbolTable.cpp
test/COFF/lto-new-symbol.ll

Index: COFF/SymbolTable.cpp

  • COFF/SymbolTable.cpp

+++ COFF/SymbolTable.cpp
@@ -276,12 +276,18 @@

if (!Body->isExternal())
  continue;
  • // Find an existing Symbol. We should not see any new symbols at

this point.

+ // Find an existing Symbol. We should not see any new undefined

symbols at

+ // this point.

StringRef Name = Body->getName();
  • Symbol *Sym = Symtab[Name];

+ Symbol *&Sym = Symtab[Name];

Move this after "if".

if (!Sym) {
  • llvm::errs() << "LTO: unexpected new symbol: " << Name << '\n';
  • return make_error_code(LLDError::BrokenFile);

+ Sym = new (Alloc) Symbol(Body);
+ if (!isa<Defined>(Body)) {
+ llvm::errs() << "LTO: undefined symbol: " << Name << '\n';
+ return make_error_code(LLDError::BrokenFile);
+ }
+ Body->setBackref(Sym);
+ continue;

}
Body->setBackref(Sym);

Index: test/COFF/lto-new-symbol.ll

  • /dev/null

+++ test/COFF/lto-new-symbol.ll
@@ -0,0 +1,16 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld -flavor link2 /out:%t.exe /entry:foo /subsystem:console %t.obj
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @foo(<4 x i32>* %p, <4 x float>* %q, i1 %t) nounwind {
+entry:
+ br label %loop
+loop:
+ store <4 x i32><i32 1073741824, i32 1073741824, i32 1073741824, i32

1073741824>, <4 x i32>* %p

+ store <4 x float><float 2.0, float 2.0, float 2.0, float 2.0>, <4 x

float>* %q

+ br i1 %t, label %loop, label %ret
+ret:
+ ret void
+}

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/
ruiu added a comment.Jun 8 2015, 6:33 PM

2015/06/08 午後5:23 "Peter Collingbourne" <peter@pcc.me.uk>:

Hi ruiu,

The LLVM code generator can sometimes synthesize symbols, such as SSE
constants, that are not visible via the LTOModule interface. Allow such
symbols so long as they have definitions.

http://reviews.llvm.org/D10331

Files:

COFF/SymbolTable.cpp
test/COFF/lto-new-symbol.ll

Index: COFF/SymbolTable.cpp

  • COFF/SymbolTable.cpp

+++ COFF/SymbolTable.cpp
@@ -276,12 +276,18 @@

if (!Body->isExternal())
  continue;
  • // Find an existing Symbol. We should not see any new symbols at

this point.

+ // Find an existing Symbol. We should not see any new undefined

symbols at

+ // this point.

StringRef Name = Body->getName();
  • Symbol *Sym = Symtab[Name];

+ Symbol *&Sym = Symtab[Name];

if (!Sym) {
  • llvm::errs() << "LTO: unexpected new symbol: " << Name << '\n';
  • return make_error_code(LLDError::BrokenFile);

+ Sym = new (Alloc) Symbol(Body);

I'm sorry, I was talking about this line.

+ if (!isa<Defined>(Body)) {
+ llvm::errs() << "LTO: undefined symbol: " << Name << '\n';
+ return make_error_code(LLDError::BrokenFile);
+ }
+ Body->setBackref(Sym);
+ continue;

}
Body->setBackref(Sym);

Index: test/COFF/lto-new-symbol.ll

  • /dev/null

+++ test/COFF/lto-new-symbol.ll
@@ -0,0 +1,16 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld -flavor link2 /out:%t.exe /entry:foo /subsystem:console %t.obj
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @foo(<4 x i32>* %p, <4 x float>* %q, i1 %t) nounwind {
+entry:
+ br label %loop
+loop:
+ store <4 x i32><i32 1073741824, i32 1073741824, i32 1073741824, i32

1073741824>, <4 x i32>* %p

+ store <4 x float><float 2.0, float 2.0, float 2.0, float 2.0>, <4 x

float>* %q

+ br i1 %t, label %loop, label %ret
+ret:
+ ret void
+}

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/
This revision was automatically updated to reflect the committed changes.