Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang++ -opt-bisect-limit SIGSEGV with Emulated TLS #41554

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR42584
Status NEW
Importance P normal
Reported by Kurt Miller (bsdkurt@gmail.com)
Reported on 2019-07-11 07:19:03 -0700
Last modified on 2019-07-12 08:32:15 -0700
Version 8.0
Hardware PC OpenBSD
CC bsdkurt@gmail.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments llvm.42584.diff (667 bytes, text/plain)
Blocks
Blocked by
See also
Summary:
On OpenBSD/i386 -current with clang++ 8.0.0 I hit a SIGSEGV in clang++ while
using -opt-bisect-limit. I believe this is due to
llvm/lib/CodeGen/LowerEmuTLS.cpp incorrectly skipping this pass when it is
required on platforms that use Emulated TLS like OpenBSD.

Removing the following two lines:

  if (skipModule(M))
    return false;

in LowerEmuTLS::runOnModule(Module &M) corrects the segfault.

Details:
BISECT: NOT running pass (17334) Machine Copy Propagation Pass on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17335) Post RA top-down list latency scheduler on
function (_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17336) Branch Probability Basic Block Placement on
function (_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17337) ReachingDefAnalysis on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17338) X86 Execution Dependency Fix on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17339) BreakFalseDeps on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17340) X86 Byte/Word Instruction Fixup on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17341) X86 Atom pad short functions on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17342) X86 LEA Fixup on function
(_ZN6Thread25set_current_resource_markEP12ResourceMark)
BISECT: NOT running pass (17343) X86 DAG->DAG Instruction Selection on function
(_ZN6Thread15current_or_nullEv)
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see
invocation)
OpenBSD clang version 8.0.0 (tags/RELEASE_800/final) (based on LLVM 8.0.0)
Target: i386-unknown-openbsd6.5
Thread model: posix
InstalledDir: /usr/bin
clang++: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and
associa
ted run script.
clang++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/stubRoutines-304a42.cpp
clang++: note: diagnostic msg: /tmp/stubRoutines-304a42.sh
clang++: note: diagnostic msg:

********************

(gdb) bt
#0  llvm::SelectionDAG::getGlobalAddress (this=0x3f499400, GV=0x0, DL=...,
VT=..., Offset=0, isTargetGA=<optimized out>,
    TargetFlags=<optimized out>) at /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1339
#1  0x01b98e36 in LowerToTLSEmulatedModel () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:5231
#2  0x01cee0e9 in LowerGlobalTLSAddress () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/Target/X86/X86ISelLowering.cpp:17054
#3  0x01d180fc in LowerOperation () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/Target/X86/X86ISelLowering.cpp:26204
#4  0x01ec7895 in LegalizeOp () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1213
#5  0x01ec71c6 in Legalize () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:4578
#6  0x01b2c080 in CodeGenAndEmitDAG () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:864
#7  0x01b2acfc in SelectAllBasicBlocks () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1784
#8  0x01b280fd in runOnMachineFunction () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:471
#9  0x00ebb2a6 in runOnMachineFunction () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:185
#10 0x011047d7 in runOnFunction () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/MachineFunctionPass.cpp:74
#11 0x010ed420 in runOnFunction () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/IR/LegacyPassManager.cpp:1644
#12 0x010ed6b9 in runOnModule () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/IR/LegacyPassManager.cpp:1679
#13 0x010eda8d in runOnModule () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/IR/LegacyPassManager.cpp:1744
#14 run () at
/usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/IR/LegacyPassManager.cpp:1857
#15 0x010ee0a1 in llvm::legacy::PassManager::run(llvm::Module&) ()
    at /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/IR/LegacyPassManager.cpp:1888
#16 0x024bff59 in EmitAssembly () at
/usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:882
#17 EmitBackendOutput () at
/usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:1318
#18 0x024b9433 in HandleTranslationUnit ()
    at /usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:293
#19 0x0292b18a in ParseAST () at
/usr/src/gnu/usr.bin/clang/libclangParse/../../../llvm/tools/clang/lib/Parse/ParseAST.cpp:170
#20 0x0217fbcc in ExecuteAction () at
/usr/src/gnu/usr.bin/clang/libclangFrontend/../../../llvm/tools/clang/lib/Frontend/FrontendAction.cpp:1036
#21 0x024b7c25 in ExecuteAction () at
/usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1048
#22 0x0217f6d2 in Execute () at
/usr/src/gnu/usr.bin/clang/libclangFrontend/../../../llvm/tools/clang/lib/Frontend/FrontendAction.cpp:935
#23 0x02138492 in ExecuteAction () at
/usr/src/gnu/usr.bin/clang/libclangFrontend/../../../llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:955
#24 0x02130ec0 in ExecuteCompilerInvocation ()
    at /usr/src/gnu/usr.bin/clang/libclangFrontendTool/../../../llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:268
#25 0x00e896e4 in cc1_main () at
/usr/src/gnu/usr.bin/clang/clang/../../../llvm/tools/clang/tools/driver/cc1_main.cpp:219
#26 0x00e87db0 in ExecuteCC1Tool () at
/usr/src/gnu/usr.bin/clang/clang/../../../llvm/tools/clang/tools/driver/driver.cpp:310
#27 main () at
/usr/src/gnu/usr.bin/clang/clang/../../../llvm/tools/clang/tools/driver/driver.cpp:382
(gdb) frame 0
#0  llvm::SelectionDAG::getGlobalAddress (this=0x3f499400, GV=0x0, DL=...,
VT=..., Offset=0, isTargetGA=<optimized out>,
    TargetFlags=<optimized out>) at /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1339
1339      unsigned BitWidth = getDataLayout().getPointerTypeSizeInBits(GV-
>getType());
(gdb) list
1334                                           unsigned char TargetFlags) {
1335      assert((TargetFlags == 0 || isTargetGA) &&
1336             "Cannot set target flags on target-independent globals");
1337
1338      // Truncate (with sign-extension) the offset value to the pointer size.
1339      unsigned BitWidth = getDataLayout().getPointerTypeSizeInBits(GV-
>getType());
1340      if (BitWidth < 64)
1341        Offset = SignExtend64(Offset, BitWidth);
1342
1343      unsigned Opc;

Using -opt-bisect-limit I found that when the following pass is not run the
segfault occurs:

BISECT: NOT running pass (10458) Add __emutls_[vt]. variables for emultated TLS
model on module (/home/truk/jdk/openjdk-
jdk11u/src/hotspot/share/runtime/stubRoutines.cpp)

Increasing the limit to include this pass prevents the segfault.

The preprocessed source for this crash is 11MB and is too big to attach (even
when compressed). I'll make the files available for download shortly.
Quuxplusone commented 5 years ago

The preprocessed source and build script can be downloaded here:

http://www.intricatesoftware.com/distfiles/clang++.openjdk.stubRoutines.tar.gz

Quuxplusone commented 5 years ago

Attached llvm.42584.diff (667 bytes, text/plain): Don't skip module LowerEmuTLS

Quuxplusone commented 5 years ago
Minimal test case on platforms with emulated TLS model:

======= minimal.cpp =============
class Minimal {
private:
  static __thread int *tls1;

public:
  static int* get_tls1() {
    return tls1;
  }

};

int main() {
  return (int)Minimal::get_tls1();
}
==================================

clang++ -c -O2 -mllvm -opt-bisect-limit=95 -o minimal minimal.cpp

Adjust limit so that it is before:
Add __emutls_[vt]. variables for emultated TLS model on module (minimal.cpp)

and clang++ will segfault.
Quuxplusone commented 5 years ago
Sorry I posted the wrong version of the code. Here is right one:

======= minimal.cpp ===========
class Minimal {
private:
  static __thread int tls1;

public:
  static int get_tls1() {
    return tls1;
  }

};

int main() {
  return Minimal::get_tls1();
}
===============================