<p dir="ltr">__chkstk is a special symbol. Does the code generator introduce arbitrary symbols? If not (if it could introduce only a limited set of symbols), we may want to resolve them unconditionally as if they were specified with /include.</p>
<div class="gmail_quote">2015/06/08 午後6:00 "Peter Collingbourne" <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi ruiu,<br>
<br>
The code generator may create references to runtime library symbols such as<br>
__chkstk which were not visible via LTOModule. Handle these cases by loading<br>
the object file from the library, but abort if we end up having loaded any<br>
bitcode objects.<br>
<br>
Because loading the object file may have introduced new undefined references,<br>
call reportRemainingUndefines again to detect and report them.<br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10332&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=qSioAEl9drEtIonxJbqqOn1AXqQsXaZEbY38ekA7pCw&s=WPe0lFFvXBqM6iyRPy7f2T-2NdBR5rhUIE26fhzw_Ro&e=" target="_blank">http://reviews.llvm.org/D10332</a><br>
<br>
Files:<br>
  COFF/SymbolTable.cpp<br>
  test/COFF/Inputs/lto-chkstk-chkstk.s<br>
  test/COFF/Inputs/lto-chkstk-foo.s<br>
  test/COFF/lto-chkstk.ll<br>
<br>
Index: COFF/SymbolTable.cpp<br>
===================================================================<br>
--- COFF/SymbolTable.cpp<br>
+++ COFF/SymbolTable.cpp<br>
@@ -307,8 +307,27 @@<br>
         return make_error_code(LLDError::BrokenFile);<br>
       }<br>
     }<br>
+<br>
+    // We may see new references to runtime library symbols such as __chkstk<br>
+    // here. These symbols must be wholly defined in non-bitcode files.<br>
+    if (auto *B = dyn_cast<Lazy>(Sym->Body)) {<br>
+      unsigned NumBitcodeFiles = BitcodeFiles.size();<br>
+      auto EC = addMemberFile(B);<br>
+      if (EC)<br>
+        return EC;<br>
+      if (BitcodeFiles.size() != NumBitcodeFiles) {<br>
+        llvm::errs()<br>
+            << "LTO: late loaded symbol created new bitcode reference: " << Name<br>
+            << "\n";<br>
+        return make_error_code(LLDError::BrokenFile);<br>
+      }<br>
+    }<br>
   }<br>
<br>
+  // New runtime library symbol references may have created undefined references.<br>
+  if (reportRemainingUndefines())<br>
+    return make_error_code(LLDError::BrokenFile);<br>
+<br>
   return std::error_code();<br>
 }<br>
<br>
Index: test/COFF/Inputs/lto-chkstk-chkstk.s<br>
===================================================================<br>
--- /dev/null<br>
+++ test/COFF/Inputs/lto-chkstk-chkstk.s<br>
@@ -0,0 +1,3 @@<br>
+.globl __chkstk<br>
+__chkstk:<br>
+ret<br>
Index: test/COFF/Inputs/lto-chkstk-foo.s<br>
===================================================================<br>
--- /dev/null<br>
+++ test/COFF/Inputs/lto-chkstk-foo.s<br>
@@ -0,0 +1,3 @@<br>
+.globl foo<br>
+foo:<br>
+ret<br>
Index: test/COFF/lto-chkstk.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/COFF/lto-chkstk.ll<br>
@@ -0,0 +1,17 @@<br>
+; RUN: llvm-as -o %t.obj %s<br>
+; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/lto-chkstk-foo.obj %S/Inputs/lto-chkstk-foo.s<br>
+; RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/lto-chkstk-chkstk.obj %S/Inputs/lto-chkstk-chkstk.s<br>
+; RUN: llvm-ar cru %t.lib %T/lto-chkstk-chkstk.obj<br>
+; RUN: lld -flavor link2 /out:%t.exe /entry:main /subsystem:console %t.obj %T/lto-chkstk-foo.obj %t.lib<br>
+<br>
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc"<br>
+<br>
+define void @main() {<br>
+entry:<br>
+  %array4096 = alloca [4096 x i8]<br>
+  call void @foo([4096 x i8]* %array4096)<br>
+  ret void<br>
+}<br>
+<br>
+declare void @foo([4096 x i8]*)<br>
<br>
EMAIL PREFERENCES<br>
  <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_settings_panel_emailpreferences_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=qSioAEl9drEtIonxJbqqOn1AXqQsXaZEbY38ekA7pCw&s=eVrSV18W3zfXLbxk2adLBjyr3hS6kmO0bgsgbTWDI2c&e=" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</blockquote></div>