llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.6k stars 11.82k forks source link

vtable `llvm::raw_string_ostream` missing from assembly on powerpc-darwin8 (MC) #14951

Closed llvmbot closed 2 months ago

llvmbot commented 11 years ago
Bugzilla Link 14579
Version trunk
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @hfinkel,@iains,@isanbard

Extended Description

from bug 14387 (originally about .line directives in asm): I built r169799 on powerpc-darwin8, and started a stage 2 build using -gdwarf2 -no-integrated-as.

[  0%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o
cd /Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Support && /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++   -DLLVMSupport_EXPORTS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-common -no-integrated-as -fPIC -fvisibility-inlines-hidden -fno-rtti -O2 -gdwarf2 -fPIC -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Support -I/Users/fang/local/src/LLVM-svn/llvm/lib/Support -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/include -I/Users/fang/local/src/LLVM-svn/llvm/include    -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fno-exceptions -o CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o -c /Users/fang/local/src/LLVM-svn/llvm/lib/Support/CommandLine.cpp
clang-3: warning: argument unused during compilation: '-gdwarf2'
/tmp/CommandLine-qnrm7J.s:11052:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L95$pb"
/tmp/CommandLine-qnrm7J.s:11052:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression
/tmp/CommandLine-qnrm7J.s:11051:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L95$pb"
/tmp/CommandLine-qnrm7J.s:11051:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression
/tmp/CommandLine-qnrm7J.s:10812:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L94$pb"
/tmp/CommandLine-qnrm7J.s:10812:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression
/tmp/CommandLine-qnrm7J.s:10811:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L94$pb"
/tmp/CommandLine-qnrm7J.s:10811:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression

Apparently, llvm::raw_string_ostream is unimplemented (MC) for powerpc-darwin8.

llvmbot commented 9 years ago

Note: Iain and Rafael discussed this issue offline, and Rafael committed r220580 (trunk, 3.6) that helps with this, by introducing isDeclarationForLinker. Modernized patch would need to call that instead.

I am currently testing bootstrap on 3.4.2 on powerpc-darwin8 with the previous patch...

Well, it did manage to bootstrap 3.4.2 through all 3 stages (even a 4th stage) at -O2 -no-integrated-as, but LLVM and clang tests fared worse than stage1's. Still, this is progress!

I noticed that trunk cleaned up with calls to

bool isDecl = GV->isDeclaration();

there is now a GlobalValue::isDeclarationForLinker() that essentially does hasAvailableExternallyLinkage() || isDeclaration().

Should we now use:

bool isDecl = GV->isDeclarationForLinker();

at the same spot in PPCSubtarget.cpp?

Very likely yes, that is what every other backend is doing I think.

llvmbot commented 9 years ago

Note: Iain and Rafael discussed this issue offline, and Rafael committed r220580 (trunk, 3.6) that helps with this, by introducing isDeclarationForLinker. Modernized patch would need to call that instead.

I am currently testing bootstrap on 3.4.2 on powerpc-darwin8 with the previous patch...

Well, it did manage to bootstrap 3.4.2 through all 3 stages (even a 4th stage) at -O2 -no-integrated-as, but LLVM and clang tests fared worse than stage1's. Still, this is progress!

I noticed that trunk cleaned up with calls to

bool isDecl = GV->isDeclaration();

there is now a GlobalValue::isDeclarationForLinker() that essentially does hasAvailableExternallyLinkage() || isDeclaration().

Should we now use:

bool isDecl = GV->isDeclarationForLinker();

at the same spot in PPCSubtarget.cpp?

llvmbot commented 9 years ago

Note: Iain and Rafael discussed this issue offline, and Rafael committed r220580 (trunk, 3.6) that helps with this, by introducing isDeclarationForLinker. Modernized patch would need to call that instead.

I am currently testing bootstrap on 3.4.2 on powerpc-darwin8 with the previous patch...

llvmbot commented 9 years ago

Iain shared with me this patch, which allows the test case in comment 30 to pass at -O1! Iain intends to submit this upstream. Huzzah!

diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp index d6b964d..fa46f91 100644 --- a/lib/Target/PowerPC/PPCSubtarget.cpp +++ b/lib/Target/PowerPC/PPCSubtarget.cpp @@ -182,7 +182,8 @@ bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV, return false; // If symbol visibility is hidden, the extra load is not needed if // the symbol is definitely defined in the current translation unit.

llvmbot commented 10 years ago

Not sure if this helps, but for comparison, gcc-4.0 -O1 gives the following asm:

% gcc -v -save-temps -O1 -DPIC -fno-common -c llvm/llvm-bugzilla-archive#14579 b.cpp -o llvm/llvm-bugzilla-archive#14579 .gcc-o Using built-in specs. Target: powerpc-apple-darwin8 Configured with: /var/tmp/gcc/gcc-5370~2/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --target=powerpc-apple-darwin8 Thread model: posix gcc version 4.0.1 (Apple Computer, Inc. build 5370) /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/cc1plus -E -quiet -v -DDYNAMIC -DPIC llvm/llvm-bugzilla-archive#14579 b.cpp -fPIC -fno-common -O1 -fpch-preprocess -D__private_extern__=extern -o llvm/llvm-bugzilla-archive#14579 b.ii ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../../powerpc-apple-darwin8/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include /usr/include /System/Library/Frameworks /Library/Frameworks End of search list. /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/cc1plus -fpreprocessed llvm/llvm-bugzilla-archive#14579 b.ii -fPIC -quiet -dumpbase llvm/llvm-bugzilla-archive#14579 b.cpp -auxbase-strip llvm/llvm-bugzilla-archive#14579 .gcc-o -O1 -version -fno-common -D__private_extern__=extern -o llvm/llvm-bugzilla-archive#14579 b.s GNU C++ version 4.0.1 (Apple Computer, Inc. build 5370) (powerpc-apple-darwin8) compiled by GNU C version 4.0.1 (Apple Computer, Inc. build 5370). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 83c106e4a4e660b766abd877880d9b62 /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/as -arch ppc -o llvm/llvm-bugzilla-archive#14579 .gcc-o llvm/llvm-bugzilla-archive#14579 b.s

% cat llvm/llvm-bugzilla-archive#14579 b.s .section TEXT,text,regular,pure_instructions .section TEXT,picsymbolstub1,symbol_stubs,pure_instructions,32 .machine ppc .mod_initfunc .align 2 .long GLOBALI#14579 b.cpp_00000000_9A6A7F1F .lcomm _foo,1,0 .section TEXT,StaticInit,regular,pure_instructions .align 2 Z41static_initialization_and_destruction_0ii: LFB7: mflr r0 LCFI0: stw r31,-4(r1) LCFI1: stw r0,8(r1) LCFI2: stwu r1,-80(r1) LCFI3: bcl 20,31,"L00000000001$pb" "L00000000001$pb": mflr r31 li r0,0 ori r0,r0,65535 cmpw cr7,r4,r0 bne cr7,L5 cmpwi cr7,r3,1 bne cr7,L5 addis r3,r31,ha16(_tcf_0-"L00000000001$pb") la r3,lo16(_tcf0-"L00000000001$pb")(r3) li r4,0 addis r5,r31,ha16(Ldso_handle$non_lazy_ptr-"L00000000001$pb") lwz r5,lo16(L_dso_handle$non_lazyptr-"L00000000001$pb")(r5) bl Lcxa_atexit$stub L5: addi r1,r1,80 lwz r0,8(r1) mtlr r0 lwz r31,-4(r1) blr LFE7: .text .align 2 ___tcf_0: LFB8: mflr r0 LCFI4: stw r31,-4(r1) LCFI5: stw r0,8(r1) LCFI6: stwu r1,-80(r1) LCFI7: bcl 20,31,"L00000000002$pb" "L00000000002$pb": mflr r31 addis r3,r31,ha16(_foo-"L00000000002$pb") la r3,lo16(_foo-"L00000000002$pb")(r3) bl LZN12basic_stringIcE7nothingEv$stub addi r1,r1,80 lwz r0,8(r1) mtlr r0 lwz r31,-4(r1) blr LFE8: .section TEXT,StaticInit,regular,pureinstructions .align 2 GLOBALI#14579 b.cpp_00000000_9A6A7F1F: LFB12: mflr r0 LCFI8: stw r0,8(r1) LCFI9: stwu r1,-80(r1) LCFI10: li r3,1 li r4,0 ori r4,r4,65535 bl Z41static_initialization_and_destruction_0ii addi r1,r1,80 lwz r0,8(r1) mtlr r0 blr LFE12: Z41static_initialization_and_destruction_0ii.eh = 0 .no_dead_strip Z41static_initialization_and_destruction0ii.eh GLOBALI#14579 b.cpp_00000000_9A6A7F1F.eh = 0 .no_deadstrip GLOBALI#14579 b.cpp_00000000_9A6A7F1F.eh .section TEXT,eh_frame,coalesced,no_toc+strip_static_syms+live_support EH_frame1: .set L$set$0,LECIE1-LSCIE1 .long L$set$0 LSCIE1: .long 0x0 .byte 0x1 .ascii "zPR\0" .byte 0x1 .byte 0x7c .byte 0x41 .byte 0x6 .byte 0x9b .long L_gxx_personality_v0$non_lazyptr-. .byte 0x10 .byte 0xc .byte 0x1 .byte 0x0 .align 2 LECIE1: tcf_0.eh: LSFDE3: .set L$set$1,LEFDE3-LASFDE3 .long L$set$1 LASFDE3: .long LASFDE3-EH_frame1 .long LFB8-. .set L$set$2,LFE8-LFB8 .long L$set$2 .byte 0x0 .byte 0x4 .set L$set$3,LCFI7-LFB8 .long L$set$3 .byte 0xe .byte 0x50 .byte 0x9f .byte 0x1 .byte 0x11 .byte 0x41 .byte 0x7e .align 2 LEFDE3: .section TEXT,picsymbolstub1,symbol_stubs,pure_instructions,32 .align 5 LZN12basic_stringIcE7nothingEv$stub: .indirect_symbol ZN12basic_stringIcE7nothingEv mflr r0 bcl 20,31,"L00000000001$spb" "L00000000001$spb": mflr r11 addis r11,r11,ha16(LZN12basic_stringIcE7nothingEv$lazy_ptr-"L00000000001$spb") mtlr r0 lwzu r12,lo16(LZN12basic_stringIcE7nothingEv$lazy_ptr-"L00000000001$spb")(r11) mtctr r12 bctr .lazy_symbol_pointer LZN12basic_stringIcE7nothingEv$lazy_ptr: .indirect_symbol ZN12basic_stringIcE7nothingEv .long dyld_stub_binding_helper .section TEXT,__picsymbolstub1,symbol_stubs,pureinstructions,32 .align 5 Lcxa_atexit$stub: .indirect_symbol _cxa_atexit mflr r0 bcl 20,31,"L00000000002$spb" "L00000000002$spb": mflr r11 addis r11,r11,ha16(L___cxa_atexit$lazyptr-"L00000000002$spb") mtlr r0 lwzu r12,lo16(Lcxa_atexit$lazy_ptr-"L00000000002$spb")(r11) mtctr r12 bctr .lazy_symbol_pointer L_cxa_atexit$lazy_ptr: .indirect_symbol _cxa_atexit .long dyld_stub_binding_helper .non_lazy_symbolpointer Ldso_handle$non_lazy_ptr: .indirectsymbol dso_handle .long 0 L_gxx_personality_v0$non_lazy_ptr: .indirectsymbol gxx_personality_v0 .long 0 .constructor .destructor .align 1 .subsections_via_symbols

llvmbot commented 10 years ago

Reduced test case:

% cat llvm/llvm-bugzilla-archive#14579 b.ii template class basic_string { void nothing(void); public: basic_string() { } ~basic_string() { nothing(); } }; extern template class basic_string; static basic_string foo;

invocation: % /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -v -O1 -fno-common -no-integrated-as -save-temps -fPIC -o llvm/llvm-bugzilla-archive#14579 b.o -c llvm/llvm-bugzilla-archive#14579 b.ii clang version 3.4 Target: powerpc-apple-darwin8.11.0 Thread model: posix "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name llvm/llvm-bugzilla-archive#14579 b.ii -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -target-cpu ppc -v -coverage-file /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support/#14579 b.s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4 -O1 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-fragile-10.4.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o llvm/llvm-bugzilla-archive#14579 b.s -x c++-cpp-output llvm/llvm-bugzilla-archive#14579 b.ii clang -cc1 version 3.4 based upon LLVM 3.4git-bb410b7 default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/usr/bin/as" -arch ppc -o llvm/llvm-bugzilla-archive#14579 b.o llvm/llvm-bugzilla-archive#14579 b.s llvm/llvm-bugzilla-archive#14579 b.s:21:non-relocatable subtraction expression, "ZN12basic_stringIcED1Ev" minus "L0$pb" llvm/llvm-bugzilla-archive#14579 b.s:21:symbol: "__ZN12basic_stringIcED1Ev" can't be undefined in a subtraction expression llvm/llvm-bugzilla-archive#14579 b.s:18:non-relocatable subtraction expression, "ZN12basic_stringIcED1Ev" minus "L0$pb" llvm/llvm-bugzilla-archive#14579 b.s:18:symbol: "__ZN12basic_stringIcED1Ev" can't be undefined in a subtraction expression clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

assembly: % cat llvm/llvm-bugzilla-archive#14579 b.s .machine ppc .section TEXT,textcoal_nt,coalesced,pure_instructions .section TEXT,picsymbolstub1,symbol_stubs,pure_instructions,32 .section TEXT,text,regular,pure_instructions .section TEXT,StaticInit,regular,pure_instructions .align 4 _cxx_global_var_init: ; @​cxx_global_var_init ; BB#0: ; %entry mflr r0 stw r31, -4(r1) stw r0, 8(r1) stwu r1, -64(r1) bl L0$pb L0$pb: mr r31, r1 mflr r2 addis r3, r2, ha16(L_dso_handle$non_lazy_ptr-L0$pb) addis r4, r2, ha16(ZN12basic_stringIcED1Ev-L0$pb) addis r2, r2, ha16(ZL3foo-L0$pb) lwz r5, lo16(L___dso_handle$non_lazy_ptr-L0$pb)(r3) la r3, lo16(ZN12basic_stringIcED1Ev-L0$pb)(r4) la r4, lo16(__ZL3foo-L0$pb)(r2) bl L___cxa_atexit$stub addi r1, r1, 64 lwz r0, 8(r1) lwz r31, -4(r1) mtlr r0 blr

    .align  4

GLOBALI_a: ; @​_GLOBALIa ; BB#0: ; %entry mflr r0 stw r31, -4(r1) stw r0, 8(r1) stwu r1, -64(r1) mr r31, r1 bl cxx_global_var_init addi r1, r1, 64 lwz r0, 8(r1) lwz r31, -4(r1) mtlr r0 blr

    .section        __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .align  4

L_cxa_atexit$stub: .indirectsymbol cxa_atexit mflr r0 bcl 20, 31, L_cxa_atexit$stub$tmp L_cxaatexit$stub$tmp: mflr r11 addis r11, r11, ha16(Lcxa_atexit$lazyptr-Lcxa_atexit$stub$tmp) mtlr r0 lwzu r12, lo16(L_cxa_atexit$lazyptr-Lcxa_atexit$stub$tmp)(r11) mtctr r12 bctr .section DATA,la_symbol_ptr,lazy_symbol_pointers L_cxa_atexit$lazy_ptr: .indirectsymbol cxa_atexit .long dyld_stub_binding_helper

    .section        __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
    .align  2

L_dso_handle$non_lazy_ptr: .indirectsymbol dso_handle .long 0

.subsections_via_symbols .zerofill DATA,bss,__ZL3foo,1,0 ; @​_ZL3foo .section DATA,mod_init_func,mod_init_funcs .align 2 .long GLOBALI_a

llvmbot commented 10 years ago

Though not preprocessed, the following test case triggers the problem:

include

static std::string foo;

% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ \ -DLLVMSupport_EXPORTS -D_DEBUG -DSTDC_CONSTANT_MACROS -DSTDC_FORMAT_MACROS -DSTDC_LIMIT_MACROS \ -I/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include \ -O1 -fno-common -no-integrated-as -fno-dwarf2-cfi-asm -save-temps -fPIC \ -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings \ -pedantic -Wno-long-long -Wnon-virtual-dtor -fno-rtti \ -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fPIC \ -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support \ -I/Users/fang/local/src/LLVM-svn/llvm/lib/Support \ -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/include \ -I/Users/fang/local/src/LLVM-svn/llvm/include \ -fno-exceptions \ -o CMakeFiles/LLVMSupport.dir/Debug-reduce.cpp.o \ -c /Users/fang/local/src/LLVM-svn/llvm/lib/Support/Debug-reduce.cpp Debug-reduce.s:27:non-relocatable subtraction expression, "ZNSsD1Ev" minus "L0$pb" Debug-reduce.s:27:symbol: "ZNSsD1Ev" can't be undefined in a subtraction expression Debug-reduce.s:24:non-relocatable subtraction expression, "ZNSsD1Ev" minus "L0$pb" Debug-reduce.s:24:symbol: "__ZNSsD1Ev" can't be undefined in a subtraction expression clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

I can reduce further...

llvmbot commented 10 years ago

working asm with -O1 -no-use-cxa-atexit Hi Tobias, thanks for the references. I tried your workaround -fno-use-cxa-atexit, and it compiled successfully, with the attached -save-temps .s asm, emitting a stub and lazy-ptr for __ZNSsD1Ev. Does this indicate what a proper fix could be?

llvmbot commented 10 years ago

Does it work when passing "-fno-use-cxa-atexit" to clang? That might be a workaround.

llvmbot commented 10 years ago

Glad to see progress in PowerPC Clang - looking forward to having a decent Objective-C++ compiler for PowerPC OS X (gcc doesn't seem to do that job well enough for something as complex as WebKit).

The problematic code is part of the global constructor for std::basic_string and wants to pass the destructor's address to cxa_exit(). And there is also a correctly generated lazy reference to that same destructor (and the corresponding constructor) in the code. The Mach-O docs say that "The compiler generates non-lazy symbol references for data symbols or function addresses." (see link at the bottom), which is what it might want to do here. But the Mach-O docs also say that "The compiler generates lazy symbol references when it encounters a call to a function defined in another file.", which is why there is a lazy reference in the generated code, used for calling the destructor directly from other parts of the code. Linking to the same symbol lazily and non-lazily in one compilation unit doesn't seem to make sense to me (although it might actually work). Maybe that's confusing the compiler as well. I'd think function calls should also use a non-lazy reference in case some other code in the compilation unit needs to get the address of the same function (needing a non-lazy reference).

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/indirect_addressing.html

llvmbot commented 10 years ago

another bad asm at -O1 Perhaps I got excited to soon. Elsewhere in stage-2 of powerpc-darwin8 at -O1:

make[2]: Entering directory /Volumes/Isolde/builds/LLVM/gcc40-stage2-opt-build' /Volumes/Mercedes2/sw/bin/cmake -E cmake_progress_report /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/CMakeFiles [ 0%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Debug.cpp.o cd /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support && /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -DLLVMSupport_EXPORTS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include -O1 -fno-common -no-integrated-as -fno-dwarf2-cfi-asm -save-temps -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -Wnon-virtual-dtor -fno-rtti -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fPIC -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support -I/Users/fang/local/src/LLVM-svn/llvm/lib/Support -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/include -I/Users/fang/local/src/LLVM-svn/llvm/include -fno-exceptions -o CMakeFiles/LLVMSupport.dir/Debug.cpp.o -c /Users/fang/local/src/LLVM-svn/llvm/lib/Support/Debug.cpp Debug.s:214:non-relocatable subtraction expression, "__ZNSsD1Ev" minus "L8$pb" Debug.s:214:symbol: "__ZNSsD1Ev" can't be undefined in a subtraction expression Debug.s:211:non-relocatable subtraction expression, "__ZNSsD1Ev" minus "L8$pb" Debug.s:211:symbol: "__ZNSsD1Ev" can't be undefined in a subtraction expression clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation) make[2]: *** [lib/Support/CMakeFiles/LLVMSupport.dir/Debug.cpp.o] Error 1 make[2]: Leaving directory/Volumes/Isolde/builds/LLVM/gcc40-stage2-opt-build' make[1]: [lib/Support/CMakeFiles/LLVMSupport.dir/all] Error 2 make[1]: Leaving directory `/Volumes/Isolde/builds/LLVM/gcc40-stage2-opt-build' make: [all] Error 2

% echo __ZNSsD1Ev | c++filt std::basic_string<char, std::char_traits, std::allocator >::~basic_string()

Using a slightly newer assembler from odcctools-2009 doesn't help either.

compiled with -v shows: "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple powerpc-apple-macosx10.4.0 -E -disable-free -main-file-name Debug.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support/Debug.ii -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -D LLVMSupport_EXPORTS -D _DEBUG -D STDC_CONSTANT_MACROS -D STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include -I /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support -I /Users/fang/local/src/LLVM-svn/llvm/lib/Support -I /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/include -I /Users/fang/local/src/LLVM-svn/llvm/include -O1 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-long-long -Wnon-virtual-dtor -pedantic -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support -ferror-limit 19 -fmessage-length 100 -fvisibility-inlines-hidden -mstackrealign -fblocks -fblocks-runtime-optional -fno-rtti -fobjc-runtime=macosx-10.4.0 -fencode-extended-block-signature -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o Debug.ii -x c++ /Users/fang/local/src/LLVM-svn/llvm/lib/Support/Debug.cpp clang -cc1 version 3.5 based upon LLVM 3.5git-5247dc3 default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/Developer/SDKs/MacOSX10.4u.sdk/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support /Users/fang/local/src/LLVM-svn/llvm/lib/Support /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/include /Users/fang/local/src/LLVM-svn/llvm/include /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0 /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/powerpc-apple-darwin8 /Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5/include /Developer/SDKs/MacOSX10.4u.sdk/usr/include /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks (framework directory) /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks (framework directory) End of search list. "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.5" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name Debug.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support/Debug.s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5 -O1 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-long-long -Wnon-virtual-dtor -pedantic -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /Users/fang/local/src/LLVM-svn/gcc40-stage2-opt-build/lib/Support -ferror-limit 19 -fmessage-length 100 -fvisibility-inlines-hidden -mstackrealign -fblocks -fblocks-runtime-optional -fno-rtti -fobjc-runtime=macosx-10.4.0 -fencode-extended-block-signature -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o Debug.s -x c++-cpp-output Debug.ii clang -cc1 version 3.5 based upon LLVM 3.5git-5247dc3 default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.5/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/usr/bin/as" -arch ppc -o CMakeFiles/LLVMSupport.dir/Debug.cpp.o Debug.s Debug.s:214:non-relocatable subtraction expression, "ZNSsD1Ev" minus "L8$pb" Debug.s:214:symbol: "ZNSsD1Ev" can't be undefined in a subtraction expression Debug.s:211:non-relocatable subtraction expression, "ZNSsD1Ev" minus "L8$pb" Debug.s:211:symbol: "ZNSsD1Ev" can't be undefined in a subtraction expression clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)

If I switch to -integrated-as, I get a similar error: clang -cc1as: fatal error: error in backend: symbol '__ZNSsD1Ev' can not be undefined in a subtraction expression

The offending -O1 asm excerpt looks like: .section TEXT,StaticInit,regular,pure_instructions .align 4 _cxx_global_var_init5: ; @​cxx_global_var_init5 ; BB#0: ; %entry ... L8$pb: ... addis r3, r29, ha16(ZNSsD1Ev-L8$pb) mr r4, r30 lwz r5, lo16(L___dso_handle$non_lazy_ptr-L8$pb)(r2) la r3, lo16(ZNSsD1Ev-L8$pb)(r3) bl L___cxa_atexit$stub ... blr

However, -O0 (which works) produces: ... addis r3, r2, ha16(LZNSsD1Ev$non_lazy_ptr-L9$pb) addis r4, r2, ha16(L___dso_handle$non_lazy_ptr-L9$pb) lwz r3, lo16(LZNSsD1Ev$non_lazy_ptr-L9$pb)(r3) lwz r5, lo16(L___dso_handle$non_lazy_ptr-L9$pb)(r4) ...

    .section        __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
    .align  2
    ...

L__ZNSsD1Ev$non_lazy_ptr: .indirect_symbol __ZNSsD1Ev .long 0

Note the use of L...$non_lazy_ptr.

llvmbot commented 10 years ago

Suddenly, as of r197897, the reduced test case now works. The one missing label/symbol now has a proper declaration, even at -O1.

% diff -u old.s new.s

@@ -104,6 +104,9 @@

.section    __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
.align  2

+L__ZTV4Base$non_lazy_ptr:

Again, thanks goes out to whomever fixed this. I'd still like to know which patch(es) in recent months would have affected this, so that I could back-port the fix the powerpc-darwin8-rel-3.4 release branch.

llvmbot commented 11 years ago

Does the same file compile with -fno-PIC instead of -fPIC ? And what about -mdynamic-no-pic instead?

Application binaries should link well using -fno-PIC while dynamic libraries need -mdynamic-no-pic or -fPIC in order to be linked, the latter being only useful for libraries that are really shared by different applications, like the c/c++/objc runtime libraries for example, as all applications will then use the same code loaded at the same address, hence saving RAM.

-fPIC will result in slower code compared to -mdynamic-no-pic , while -fno-PIC should be the fastest.

llvmbot commented 11 years ago

Since it's related to -fPIC, it's probably a Darwin-only issue. From what I've seen in the code, PIC is only currently implemented for Darwin in the PPC back end. You may be on your own here... :( Not much to do but start turning on debug dumps and look for clues.

llvmbot commented 11 years ago

Ping? Any diagnosis on this issue? (I hope this can be fixed in time for 3.3.)

llvmbot commented 11 years ago

bad PPC asm produced with -O1 -fno-common Produced by:

~/local/src/LLVM-svn/gcc40-cmake-build/bin/clang++ -v -fno-common -no-integrated-as -save-temps -O1 -c llvm/llvm-bugzilla-archive#14579 .cpp -o llvm/llvm-bugzilla-archive#14579 .o1 clang version 3.3 Target: powerpc-apple-darwin8.11.0 Thread model: posix "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1" -cc1 -triple powerpc-apple-macosx10.4.0 -E -disable-free -main-file-name llvm/llvm-bugzilla-archive#14579 .cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Users/fang/temp/clang/#14579 /#14579 .ii -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -O1 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fdebug-compilation-dir /Users/fang/temp/clang/#14579 -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o llvm/llvm-bugzilla-archive#14579 .ii -x c++ llvm/llvm-bugzilla-archive#14579 .cpp clang -cc1 version 3.3 based upon LLVM 3.3svn default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name llvm/llvm-bugzilla-archive#14579 .cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Users/fang/temp/clang/#14579 /#14579 .s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -O1 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fdebug-compilation-dir /Users/fang/temp/clang/#14579 -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o llvm/llvm-bugzilla-archive#14579 .s -x c++-cpp-output llvm/llvm-bugzilla-archive#14579 .ii clang -cc1 version 3.3 based upon LLVM 3.3svn default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/usr/bin/as" -arch ppc -o llvm/llvm-bugzilla-archive#14579 .o1 llvm/llvm-bugzilla-archive#14579 .s llvm/llvm-bugzilla-archive#14579 .s:63:non-relocatable subtraction expression, "ZTV4Base" minus "L2$pb" llvm/llvm-bugzilla-archive#14579 .s:63:symbol: "ZTV4Base" can't be undefined in a subtraction expression llvm/llvm-bugzilla-archive#14579 .s:62:non-relocatable subtraction expression, "ZTV4Base" minus "L2$pb" llvm/llvm-bugzilla-archive#14579 .s:62:symbol: "ZTV4Base" can't be undefined in a subtraction expression clang-3.1: error: assembler command failed with exit code 1 (use -v to see invocation) make: *** [#14579 .o1] Error 1

hfinkel commented 11 years ago

Still problematic at r179187. Same issue, asm rejected because no "vtable for Base" symbol is declared, though it is referenced.

Hal, or anyone with PPC, can you post the resulting asm of compiling: class Class; struct Base { virtual void foo(); }; template struct Derived : Base { Derived(const Class&) { } };

with: clang++ -fno-common -no-integrated-as -O1 -save-temps -c

Does the resulting .s assemble fine?

Can you attach the .s file that your clang produces? This works just fine on PPC64/Linux. Could it be a Darwin-specific issue?

llvmbot commented 11 years ago

also -fPIC on systems where PIC is not default. The error occurs in relocatable assembly.

llvmbot commented 11 years ago

Still problematic at r179187. Same issue, asm rejected because no "vtable for Base" symbol is declared, though it is referenced.

Hal, or anyone with PPC, can you post the resulting asm of compiling: class Class; struct Base { virtual void foo(); }; template struct Derived : Base { Derived(const Class&) { } };

with: clang++ -fno-common -no-integrated-as -O1 -save-temps -c

Does the resulting .s assemble fine?

llvmbot commented 11 years ago

This error keeps triggering when I compile various C++ sources with my stage 1 clang++.

Escalating priority (for me) -- this pretty much precludes using the stage 1 clang from compiling critical components such as libcxxabi and llvm in stage 2 without resorting to -O0. The goal is to self-host clang using at least a reasonable level of optimization like -O2.

llvmbot commented 11 years ago

Using this test case: class Class; struct Base { virtual void foo(); }; template struct Derived : Base { Derived(const Class&) { } }; template class Derived;

The -O1 asm (demangled through c++filt) contains: ... .globl Base::Base() .weak_definition Base::Base() .align 4 Base::Base(): ; @​_ZN4BaseC2Ev ; BB#0: ; %entry mflr r0 stw r0, 8(r1) bl L2$pb L2$pb: mflr r2 addis r2, r2, ha16(vtable for Base-L2$pb) la r2, lo16(vtable for Base-L2$pb)(r2) addi r2, r2, 8 stw r2, 0(r3) lwz r0, 8(r1) mtlr r0 blr ...

again, with no declaration of 'vtable for Base'.

The asm from -O0 looks quite different: ... .globl Base::Base() .weak_definition Base::Base() .align 4 Base::Base(): ; @​_ZN4BaseC2Ev ; BB#0: ; %entry mflr r0 stw r0, 8(r1) bl L2$pb L2$pb: mflr r2 addis r2, r2, ha16(LZTV4Base$non_lazy_ptr-L2$pb) lwz r2, lo16(LZTV4Base$non_lazy_ptr-L2$pb)(r2) stw r3, -8(r1) addi r2, r2, 8 mr r4, r3 stw r2, 0(r3) stw r4, -12(r1) ; 4-byte Folded Spill lwz r0, 8(r1) mtlr r0 blr ... .section DATA,nl_symbol_ptr,non_lazy_symbol_pointers .align 2 L__ZTV4Base$non_lazy_ptr: .indirect_symbol vtable for Base ...

vtable for Base is declared as an indirect symbol, but never used. In side the default constructor Base::Base(), it references L__ZTV4Base$non_lazy_ptr, the label for the location of the indirect symbol.

llvmbot commented 11 years ago

I'm having trouble reducing this test case any further:

% cat CommandLine.cpp class Class; struct Base { virtual void foo(); }; template struct Derived : Base { Derived(const T&) { } }; template class Derived;

My delta script is: $build1dir/bin/clang++ -fno-common -no-integrated-as -O1 -fPIC \ -o CommandLine.o -c CommandLine.cpp -save-temps 2>&1 | grep -q "symbol:.*undefined in a subtraction expression"

My observations:

I've tried the following, but they fail to trigger the bug:

Replacing Derived(const T&) with Derived(const Class&) (nothing depends on T) also triggers the bug:

class Class; struct Base { virtual void foo(); }; template struct Derived : Base { Derived(const Class&) { } }; template class Derived;

Where would I go about poking around to see what went wrong? C++ AST? CodeGen? Optimizer (since -O1 breaks this)?

llvmbot commented 11 years ago

I tried compiling with -target powerpc-linux-gnu (cross-compile) for comparison:

% cat CommandLine-powerpc-linux-gnu.s .file "CommandLine.ii" .section .text.ZN7DerivedI5ClassEC1ERKS0,"axG",@progbits,ZN7DerivedI5ClassEC1ERKS0,comdat .weak ZN7DerivedI5ClassEC1ERKS0 .align 2 .type ZN7DerivedI5ClassEC1ERKS0,@function ZN7DerivedI5ClassEC1ERKS0: mflr 0 stw 31, -4(1) stw 0, 4(1) stwu 1, -16(1) mr 31, 1 bl ZN7DerivedI5ClassEC2ERKS0 addi 1, 1, 16 lwz 0, 4(1) lwz 31, -4(1) mtlr 0 blr .Ltmp0: .size ZN7DerivedI5ClassEC1ERKS0, .Ltmp0-ZN7DerivedI5ClassEC1ERKS0

    .section        .text._ZN7DerivedI5ClassEC2ERKS0_,"axG",@progbits,_ZN7DerivedI5ClassEC2ERKS0_,comdat
    .weak   _ZN7DerivedI5ClassEC2ERKS0_
    .align  2
    .type   _ZN7DerivedI5ClassEC2ERKS0_,@function

ZN7DerivedI5ClassEC2ERKS0: mflr 0 stw 31, -4(1) stw 0, 4(1) stwu 1, -32(1) mr 31, 1 stw 30, 24(31) mr 30, 3 bl _ZN4BaseC2Ev lis 3, _ZTV7DerivedI5ClassE@ha la 3, _ZTV7DerivedI5ClassE@l(3) addi 3, 3, 8 stw 3, 0(30) lwz 30, 24(31) addi 1, 1, 32 lwz 0, 4(1) lwz 31, -4(1) mtlr 0 blr .Ltmp1: .size ZN7DerivedI5ClassEC2ERKS0, .Ltmp1-ZN7DerivedI5ClassEC2ERKS0

    .section        .text._ZN4BaseC2Ev,"axG",@progbits,_ZN4BaseC2Ev,comdat
    .weak   _ZN4BaseC2Ev
    .align  2
    .type   _ZN4BaseC2Ev,@function

_ZN4BaseC2Ev: lis 4, _ZTV4Base@ha la 4, _ZTV4Base@l(4) addi 4, 4, 8 stw 4, 0(3) blr .Ltmp2: .size _ZN4BaseC2Ev, .Ltmp2-_ZN4BaseC2Ev

    .type   _ZTV7DerivedI5ClassE,@object
    .section        .data.rel.ro._ZTV7DerivedI5ClassE,"aGw",@progbits,_ZTV7DerivedI5ClassE,comdat
    .weak   _ZTV7DerivedI5ClassE
    .align  2

_ZTV7DerivedI5ClassE: .long 0 .long _ZTI7DerivedI5ClassE .long _ZN4Base3fooEv .size _ZTV7DerivedI5ClassE, 12

    .type   _ZTS7DerivedI5ClassE,@object
    .section        .rodata._ZTS7DerivedI5ClassE,"aG",@progbits,_ZTS7DerivedI5ClassE,comdat
    .weak   _ZTS7DerivedI5ClassE
    .align  4

_ZTS7DerivedI5ClassE: .asciz "7DerivedI5ClassE" .size _ZTS7DerivedI5ClassE, 17

    .type   _ZTI7DerivedI5ClassE,@object
    .section        .data.rel.ro._ZTI7DerivedI5ClassE,"aGw",@progbits,_ZTI7DerivedI5ClassE,comdat
    .weak   _ZTI7DerivedI5ClassE
    .align  3

_ZTI7DerivedI5ClassE: .long _ZTVN10cxxabiv120si_class_type_infoE+8 .long _ZTS7DerivedI5ClassE .long _ZTI4Base .size _ZTI7DerivedI5ClassE, 12

_ZTV4Base is used but never declared anywhere!

llvmbot commented 11 years ago

Successfully reduced test case:

% cat CommandLine.cpp class Class; struct Base { virtual void foo(); }; template struct Derived : Base { Derived(const T&) { } }; template class Derived;

compilation: % ~/local/src/LLVM-svn/gcc40-cmake-build/bin/clang++ -fno-common -no-integrated-as -O1 -fPIC -o CommandLine.o -c CommandLine.cpp -save-temps -v clang version 3.3 Target: powerpc-apple-darwin8.11.0 Thread model: posix "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1" -cc1 -triple powerpc-apple-macosx10.4.0 -E -disable-free -main-file-name CommandLine.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Users/fang/temp/clang/delta/CommandLine.ii -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -O1 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fdebug-compilation-dir /Users/fang/temp/clang/delta -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o CommandLine.ii -x c++ CommandLine.cpp clang -cc1 version 3.3 based upon LLVM 3.3svn default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1" -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name CommandLine.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v -coverage-file /Users/fang/temp/clang/delta/CommandLine.s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -O1 -fdeprecated-macro -fno-dwarf2-cfi-asm -fno-dwarf-directory-asm -fdebug-compilation-dir /Users/fang/temp/clang/delta -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o CommandLine.s -x c++-cpp-output CommandLine.ii clang -cc1 version 3.3 based upon LLVM 3.3svn default target powerpc-apple-darwin8.11.0 ignoring nonexistent directory "/usr/local/include"

include "..." search starts here:

include <...> search starts here:

/usr/include/c++/4.0.0 /usr/include/c++/4.0.0/powerpc-apple-darwin8 /usr/include/c++/4.0.0/backward /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/usr/bin/as" -arch ppc -o CommandLine.o CommandLine.s CommandLine.s:63:non-relocatable subtraction expression, "ZTV4Base" minus "L2$pb" CommandLine.s:63:symbol: "ZTV4Base" can't be undefined in a subtraction expression CommandLine.s:62:non-relocatable subtraction expression, "ZTV4Base" minus "L2$pb" CommandLine.s:62:symbol: "ZTV4Base" can't be undefined in a subtraction expression clang-3.1: error: assembler command failed with exit code 1 (use -v to see invocation)

CommandLine.s: % cat CommandLine.s .machine ppc7400 .section TEXT,textcoal_nt,coalesced,pure_instructions .section TEXT,picsymbolstub1,symbol_stubs,pure_instructions,32 .section TEXT,text,regular,pure_instructions .section TEXT,textcoal_nt,coalesced,pure_instructions .globl ZN7DerivedI5ClassEC1ERKS0_ .weak_definition ZN7DerivedI5ClassEC1ERKS0_ .align 4 _ZN7DerivedI5ClassEC1ERKS0: ; @​ZN7DerivedI5ClassEC1ERKS0 ; BB#0: ; %entry mflr r0 stw r31, -4(r1) stw r0, 8(r1) stwu r1, -64(r1) mr r31, r1 bl L_ZN7DerivedI5ClassEC2ERKS0$stub addi r1, r1, 64 lwz r0, 8(r1) lwz r31, -4(r1) mtlr r0 blr

    .globl  __ZN7DerivedI5ClassEC2ERKS0_
    .weak_definition        __ZN7DerivedI5ClassEC2ERKS0_
    .align  4

_ZN7DerivedI5ClassEC2ERKS0: ; @​ZN7DerivedI5ClassEC2ERKS0 ; BB#0: ; %entry mflr r0 stw r31, -4(r1) stw r0, 8(r1) stwu r1, -80(r1) mr r31, r1 stw r30, 68(r31) ; 4-byte Folded Spill stw r29, 72(r31) ; 4-byte Folded Spill bl L1$pb L1$pb: mr r30, r3 mflr r29 bl LZN4BaseC2Ev$stub addis r2, r29, ha16(LZTV7DerivedI5ClassE$non_lazy_ptr-L1$pb) lwz r29, 72(r31) ; 4-byte Folded Reload lwz r2, lo16(L__ZTV7DerivedI5ClassE$non_lazy_ptr-L1$pb)(r2) addi r2, r2, 8 stw r2, 0(r30) lwz r30, 68(r31) ; 4-byte Folded Reload addi r1, r1, 80 lwz r0, 8(r1) lwz r31, -4(r1) mtlr r0 blr

    .globl  __ZN4BaseC2Ev
    .weak_definition        __ZN4BaseC2Ev
    .align  4

__ZN4BaseC2Ev: ; @​_ZN4BaseC2Ev ; BB#0: ; %entry mflr r0 stw r0, 8(r1) bl L2$pb L2$pb: mflr r2 addis r2, r2, ha16(ZTV4Base-L2$pb) la r2, lo16(ZTV4Base-L2$pb)(r2) addi r2, r2, 8 stw r2, 0(r3) lwz r0, 8(r1) mtlr r0 blr

    .section        __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .align  4

LZN4BaseC2Ev$stub: .indirect_symbol ZN4BaseC2Ev mflr r0 bl LZN4BaseC2Ev$stub$tmp LZN4BaseC2Ev$stub$tmp: mflr r11 addis r11, r11, ha16(LZN4BaseC2Ev$lazy_ptr-LZN4BaseC2Ev$stub$tmp) mtlr r0 lwzu r12, lo16(LZN4BaseC2Ev$lazy_ptr-LZN4BaseC2Ev$stub$tmp)(r11) mtctr r12 bctr .section DATA,la_symbol_ptr,lazy_symbol_pointers LZN4BaseC2Ev$lazy_ptr: .indirect_symbol __ZN4BaseC2Ev .long dyld_stub_binding_helper .section TEXT,picsymbolstub1,symbol_stubs,pure_instructions,32 .align 4 LZN7DerivedI5ClassEC2ERKS0_$stub: .indirect_symbol ZN7DerivedI5ClassEC2ERKS0_ mflr r0 bl L_ZN7DerivedI5ClassEC2ERKS0$stub$tmp LZN7DerivedI5ClassEC2ERKS0_$stub$tmp: mflr r11 addis r11, r11, ha16(LZN7DerivedI5ClassEC2ERKS0_$lazy_ptr-LZN7DerivedI5ClassEC2ERKS0_$stub$tmp) mtlr r0 lwzu r12, lo16(LZN7DerivedI5ClassEC2ERKS0_$lazy_ptr-LZN7DerivedI5ClassEC2ERKS0_$stub$tmp)(r11) mtctr r12 bctr .section DATA,la_symbol_ptr,lazy_symbol_pointers L_ZN7DerivedI5ClassEC2ERKS0$lazy_ptr: .indirect_symbol _ZN7DerivedI5ClassEC2ERKS0 .long dyld_stub_binding_helper

    .section        __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
    .align  2

L__ZTV7DerivedI5ClassE$non_lazy_ptr: .indirect_symbol __ZTV7DerivedI5ClassE .long 0

.subsections_via_symbols .section DATA,datacoal_nt,coalesced .globl ZTV7DerivedI5ClassE ; @​_ZTV7DerivedI5ClassE .weak_definition ZTV7DerivedI5ClassE .align 2 ZTV7DerivedI5ClassE: .long 0 .long ZTI7DerivedI5ClassE .long __ZN4Base3fooEv

    .section        __TEXT,__const_coal,coalesced
    .globl  __ZTS7DerivedI5ClassE   ; @&#8203;_ZTS7DerivedI5ClassE
    .weak_definition        __ZTS7DerivedI5ClassE
    .align  4

__ZTS7DerivedI5ClassE: .asciz "7DerivedI5ClassE"

    .section        __DATA,__datacoal_nt,coalesced
    .globl  __ZTI7DerivedI5ClassE   ; @&#8203;_ZTI7DerivedI5ClassE
    .weak_definition        __ZTI7DerivedI5ClassE
    .align  3

ZTI7DerivedI5ClassE: .long ZTVN10cxxabiv120si_class_type_infoE+8 .long ZTS7DerivedI5ClassE .long ZTI4Base

llvmbot commented 11 years ago

When I append -arch i386 to the options (cross-compiling) and keep -save-temps, the resulting asm file is able to assemble to an object file without error.

[/usr/bin/as from Xcode 2.5] % as -arch i386 CommandLine-i386.s -o CommandLine-i386.o

% file CommandLine-i386.o CommandLine-i386.o: Mach-O object i386

% otool -IrvV CommandLine-i386.o CommandLine-i386.o: Indirect symbols for (IMPORT,jump_table) 4 entries address index name 0x00000117 1 ZN11OptionValueI6stringEC1ERKS0_ 0x0000011c 2 _ZN11OptionValueI6stringEC2ERKS0 0x00000121 3 ZN18GenericOptionValueC2Ev 0x00000126 5 ZNK3optI6stringE8getValueEv Indirect symbols for (IMPORT,pointers) 2 entries address index name 0x0000012b 10 ZTV11OptionValueI6stringE 0x0000012f 14 ZTV18GenericOptionValue External relocation information 0 entries address pcrel length extern type scattered symbolnum/value Local relocation information 0 entries address pcrel length extern type scattered symbolnum/value Relocation information (TEXT,textcoal_nt) 8 entries address pcrel length extern type scattered symbolnum/value 0000009b False long n/a LOCSDIF True 0x0000012f False long n/a PAIR True 0x00000098 0000007b False long n/a LOCSDIF True 0x0000012b False long n/a PAIR True 0x0000006d 00000075 True long False VANILLA False 5 (IMPORT,jump_table) 0000004d True long False VANILLA False 5 (IMPORT,jump_table) 00000034 True long False VANILLA False 5 (IMPORT,jump_table) 00000017 True long False VANILLA False 5 (IMPORT,jump_table) Relocation information (DATA,datacoal_nt) 9 entries address pcrel length extern type scattered symbolnum/value 00000030 False long True VANILLA False ZTI18GenericOptionValue 0000002c False long True VANILLA False ZTS11OptionValueI6stringE 00000028 False long True VANILLA False ZTVN10cxxabiv120si_class_type_infoE 00000020 False long True VANILLA False ZN18GenericOptionValue6anchorEv 0000001c False long True VANILLA False ZTI11OptionValueI6stringE 00000014 False long True VANILLA False ZTS3optI6stringE 00000010 False long True VANILLA False ZTVN10cxxabiv117class_type_infoE 00000008 False long True VANILLA False ZNK3optI6stringE16printOptionValueEv 00000004 False long True VANILLA False ZTI3optI6stringE

Something is going wrong with PPC CodeGen with -O1...

llvmbot commented 11 years ago

After days of delta- and human- test case reduction, here is a test case that produces broken asm:

CommandLine.cpp:

class string;
 struct GenericOptionValue {
 private: virtual void anchor();
 };
 template<class DataType> struct OptionValue : GenericOptionValue {
 OptionValue(const DataType& V) {
 }
 };
 class generic_parser_base {
 };
 template<class ParserClass, class DT> void printOptionDiff(const DT &V) {
 OptionValue<DT> OV = V;
 }
 template <class DataType> class opt {
 const DataType& getValue() const {
 }
 virtual void printOptionValue() const {
 printOptionDiff<generic_parser_base>(this->getValue());
 }
 };
 template class opt<string>;

compiled with command:

clang++ -fno-common -no-integrated-as -O1 -fPIC -o CommandLine.o CommandLine.cpp -save-temps
% cat CommandLine.s
    .machine ppc7400
    .section    __TEXT,__textcoal_nt,coalesced,pure_instructions
    .section    __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .section    __TEXT,__text,regular,pure_instructions
    .section    __TEXT,__textcoal_nt,coalesced,pure_instructions
    .globl  __ZNK3optI6stringE8getValueEv
    .weak_definition    __ZNK3optI6stringE8getValueEv
    .align  4
__ZNK3optI6stringE8getValueEv:          ; @_ZNK3optI6stringE8getValueEv
; BB#0:                                 ; %entry
    nop

    .globl  __ZNK3optI6stringE16printOptionValueEv
    .weak_definition    __ZNK3optI6stringE16printOptionValueEv
    .align  4
__ZNK3optI6stringE16printOptionValueEv: ; @_ZNK3optI6stringE16printOptionValueEv
; BB#0:                                 ; %entry
    mflr r0
    stw r31, -4(r1)
    stw r0, 8(r1)
    stwu r1, -64(r1)
    mr r31, r1
    bl L__ZNK3optI6stringE8getValueEv$stub

    .globl  __Z15printOptionDiffI19generic_parser_base6stringEvRKT0_
    .weak_definition    __Z15printOptionDiffI19generic_parser_base6stringEvRKT0_
    .align  4
__Z15printOptionDiffI19generic_parser_base6stringEvRKT0_: ; @_Z15printOptionDiffI19generic_parser_base6stringEvRKT0_
; BB#0:                                 ; %entry
    mflr r0
    stw r31, -4(r1)
    stw r0, 8(r1)
    stwu r1, -80(r1)
    mr r2, r3
    mr r31, r1
    addi r3, r31, 72
    mr r4, r2
    bl L__ZN11OptionValueI6stringEC1ERKS0_$stub
    addi r1, r1, 80
    lwz r0, 8(r1)
    lwz r31, -4(r1)
    mtlr r0
    blr 

    .globl  __ZN11OptionValueI6stringEC1ERKS0_
    .weak_definition    __ZN11OptionValueI6stringEC1ERKS0_
    .align  4
__ZN11OptionValueI6stringEC1ERKS0_:     ; @_ZN11OptionValueI6stringEC1ERKS0_
; BB#0:                                 ; %entry
    mflr r0
    stw r31, -4(r1)
    stw r0, 8(r1)
    stwu r1, -64(r1)
    mr r31, r1
    bl L__ZN11OptionValueI6stringEC2ERKS0_$stub
    addi r1, r1, 64
    lwz r0, 8(r1)
    lwz r31, -4(r1)
    mtlr r0
    blr 

    .globl  __ZN11OptionValueI6stringEC2ERKS0_
    .weak_definition    __ZN11OptionValueI6stringEC2ERKS0_
    .align  4
__ZN11OptionValueI6stringEC2ERKS0_:     ; @_ZN11OptionValueI6stringEC2ERKS0_
; BB#0:                                 ; %entry
    mflr r0
    stw r31, -4(r1)
    stw r0, 8(r1)
    stwu r1, -80(r1)
    mr r31, r1
    stw r30, 68(r31)                ; 4-byte Folded Spill
    stw r29, 72(r31)                ; 4-byte Folded Spill
    bl L4$pb
L4$pb:
    mr r30, r3
    mflr r29
    bl L__ZN18GenericOptionValueC2Ev$stub
    addis r2, r29, ha16(L__ZTV11OptionValueI6stringE$non_lazy_ptr-L4$pb)
    lwz r29, 72(r31)                ; 4-byte Folded Reload
    lwz r2, lo16(L__ZTV11OptionValueI6stringE$non_lazy_ptr-L4$pb)(r2)
    addi r2, r2, 8
    stw r2, 0(r30)
    lwz r30, 68(r31)                ; 4-byte Folded Reload
    addi r1, r1, 80
    lwz r0, 8(r1)
    lwz r31, -4(r1)
    mtlr r0
    blr 

    .globl  __ZN18GenericOptionValueC2Ev
    .weak_definition    __ZN18GenericOptionValueC2Ev
    .align  4
__ZN18GenericOptionValueC2Ev:           ; @_ZN18GenericOptionValueC2Ev
; BB#0:                                 ; %entry
    mflr r0
    stw r0, 8(r1)
    bl L5$pb
L5$pb:
    mflr r2
    addis r2, r2, ha16(__ZTV18GenericOptionValue-L5$pb)
    la r2, lo16(__ZTV18GenericOptionValue-L5$pb)(r2)
    addi r2, r2, 8
    stw r2, 0(r3)
    lwz r0, 8(r1)
    mtlr r0
    blr 

    .section    __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .align  4
L__ZN11OptionValueI6stringEC1ERKS0_$stub:
    .indirect_symbol    __ZN11OptionValueI6stringEC1ERKS0_
    mflr r0
    bl L__ZN11OptionValueI6stringEC1ERKS0_$stub$tmp
L__ZN11OptionValueI6stringEC1ERKS0_$stub$tmp:
    mflr r11
    addis r11, r11, ha16(L__ZN11OptionValueI6stringEC1ERKS0_$lazy_ptr-L__ZN11OptionValueI6stringEC1ERKS0_$stub$tmp)
    mtlr r0
    lwzu r12, lo16(L__ZN11OptionValueI6stringEC1ERKS0_$lazy_ptr-L__ZN11OptionValueI6stringEC1ERKS0_$stub$tmp)(r11)
    mtctr r12
    bctr
    .section    __DATA,__la_symbol_ptr,lazy_symbol_pointers
L__ZN11OptionValueI6stringEC1ERKS0_$lazy_ptr:
    .indirect_symbol    __ZN11OptionValueI6stringEC1ERKS0_
    .long   dyld_stub_binding_helper
    .section    __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .align  4
L__ZN11OptionValueI6stringEC2ERKS0_$stub:
    .indirect_symbol    __ZN11OptionValueI6stringEC2ERKS0_
    mflr r0
    bl L__ZN11OptionValueI6stringEC2ERKS0_$stub$tmp
L__ZN11OptionValueI6stringEC2ERKS0_$stub$tmp:
    mflr r11
    addis r11, r11, ha16(L__ZN11OptionValueI6stringEC2ERKS0_$lazy_ptr-L__ZN11OptionValueI6stringEC2ERKS0_$stub$tmp)
    mtlr r0
    lwzu r12, lo16(L__ZN11OptionValueI6stringEC2ERKS0_$lazy_ptr-L__ZN11OptionValueI6stringEC2ERKS0_$stub$tmp)(r11)
    mtctr r12
    bctr
    .section    __DATA,__la_symbol_ptr,lazy_symbol_pointers
L__ZN11OptionValueI6stringEC2ERKS0_$lazy_ptr:
    .indirect_symbol    __ZN11OptionValueI6stringEC2ERKS0_
    .long   dyld_stub_binding_helper
    .section    __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .align  4
L__ZN18GenericOptionValueC2Ev$stub:
    .indirect_symbol    __ZN18GenericOptionValueC2Ev
    mflr r0
    bl L__ZN18GenericOptionValueC2Ev$stub$tmp
L__ZN18GenericOptionValueC2Ev$stub$tmp:
    mflr r11
    addis r11, r11, ha16(L__ZN18GenericOptionValueC2Ev$lazy_ptr-L__ZN18GenericOptionValueC2Ev$stub$tmp)
    mtlr r0
    lwzu r12, lo16(L__ZN18GenericOptionValueC2Ev$lazy_ptr-L__ZN18GenericOptionValueC2Ev$stub$tmp)(r11)
    mtctr r12
    bctr
    .section    __DATA,__la_symbol_ptr,lazy_symbol_pointers
L__ZN18GenericOptionValueC2Ev$lazy_ptr:
    .indirect_symbol    __ZN18GenericOptionValueC2Ev
    .long   dyld_stub_binding_helper
    .section    __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
    .align  4
L__ZNK3optI6stringE8getValueEv$stub:
    .indirect_symbol    __ZNK3optI6stringE8getValueEv
    mflr r0
    bl L__ZNK3optI6stringE8getValueEv$stub$tmp
L__ZNK3optI6stringE8getValueEv$stub$tmp:
    mflr r11
    addis r11, r11, ha16(L__ZNK3optI6stringE8getValueEv$lazy_ptr-L__ZNK3optI6stringE8getValueEv$stub$tmp)
    mtlr r0
    lwzu r12, lo16(L__ZNK3optI6stringE8getValueEv$lazy_ptr-L__ZNK3optI6stringE8getValueEv$stub$tmp)(r11)
    mtctr r12
    bctr
    .section    __DATA,__la_symbol_ptr,lazy_symbol_pointers
L__ZNK3optI6stringE8getValueEv$lazy_ptr:
    .indirect_symbol    __ZNK3optI6stringE8getValueEv
    .long   dyld_stub_binding_helper

    .section    __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
    .align  2
L__ZTV11OptionValueI6stringE$non_lazy_ptr:
    .indirect_symbol    __ZTV11OptionValueI6stringE
    .long   0

.subsections_via_symbols
    .section    __DATA,__datacoal_nt,coalesced
    .globl  __ZTV3optI6stringE      ; @_ZTV3optI6stringE
    .weak_definition    __ZTV3optI6stringE
    .align  2
__ZTV3optI6stringE:
    .long   0
    .long   __ZTI3optI6stringE
    .long   __ZNK3optI6stringE16printOptionValueEv

    .section    __TEXT,__const_coal,coalesced
    .globl  __ZTS3optI6stringE      ; @_ZTS3optI6stringE
    .weak_definition    __ZTS3optI6stringE
__ZTS3optI6stringE:
    .asciz   "3optI6stringE"

    .section    __DATA,__datacoal_nt,coalesced
    .globl  __ZTI3optI6stringE      ; @_ZTI3optI6stringE
    .weak_definition    __ZTI3optI6stringE
    .align  3
__ZTI3optI6stringE:
    .long   __ZTVN10__cxxabiv117__class_type_infoE+8
    .long   __ZTS3optI6stringE

    .globl  __ZTV11OptionValueI6stringE ; @_ZTV11OptionValueI6stringE
    .weak_definition    __ZTV11OptionValueI6stringE
    .align  2
__ZTV11OptionValueI6stringE:
    .long   0
    .long   __ZTI11OptionValueI6stringE
    .long   __ZN18GenericOptionValue6anchorEv

    .section    __TEXT,__const_coal,coalesced
    .globl  __ZTS11OptionValueI6stringE ; @_ZTS11OptionValueI6stringE
    .weak_definition    __ZTS11OptionValueI6stringE
    .align  4
__ZTS11OptionValueI6stringE:
    .asciz   "11OptionValueI6stringE"

    .section    __DATA,__datacoal_nt,coalesced
    .globl  __ZTI11OptionValueI6stringE ; @_ZTI11OptionValueI6stringE
    .weak_definition    __ZTI11OptionValueI6stringE
    .align  3
__ZTI11OptionValueI6stringE:
    .long   __ZTVN10__cxxabiv120__si_class_type_infoE+8
    .long   __ZTS11OptionValueI6stringE
    .long   __ZTI18GenericOptionValue

which the assembler errors with:

CommandLine.s:102:non-relocatable subtraction expression, "__ZTV18GenericOptionValue" minus "L5$pb"
CommandLine.s:102:symbol: "__ZTV18GenericOptionValue" can't be undefined in a subtraction expression
CommandLine.s:101:non-relocatable subtraction expression, "__ZTV18GenericOptionValue" minus "L5$pb"
CommandLine.s:101:symbol: "__ZTV18GenericOptionValue" can't be undefined in a subtraction expression
clang-3.1: error: assembler command failed with exit code 1 (use -v to see invocation)

Why is that symbol not declared anywhere?

llvmbot commented 11 years ago

And I fixed those diffs earlier this evening with the following commit on the powerpc-darwin8 branch:

https://github.com/fangism/llvm/commit/88f09754411c1c71c05c183da8f653c958cc01c3

Now a very non-trivial C++ source compiled (-O0) integrated matches non-integrated assembly! w00t!

Still reducing a test case to figure out why -O1 breaks CodeGen.

llvmbot commented 11 years ago

/usr/bin/ld is able to read the clang+as-produced (-no-integrated-as) object file without problems.

% ld -macosx_version_min 10.4 -r CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o -o foo.a

succeeds. This is a good sign CodeGen/AsmPrinting is in decent shape.

Integrated-assembly is half-working on the powerpc-darwin8 branch, which includes a draft of PPCMachObjectWriter.

Here's a comparison of taking the above CommandLine.cpp object (compiled with -O0), one produced directly by clang and the other produced by clang -no-integrated-as +as. The otool dump comparison:

% diff -u CommandLine-as.cpp.otooldump CommandLine.cpp.otooldump
--- CommandLine-as.cpp.otooldump        2013-03-14 15:36:43.000000000 -0700
+++ CommandLine.cpp.otooldump   2013-03-14 15:35:54.000000000 -0700
@@ -1,4 +1,4 @@
-CommandLine-O0-as.o:
+CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o:
 Indirect symbols for (__TEXT,__picsymbolstub1) 756 entries
 address    index name
 0x0001db90  1049 _AnnotateHappensAfter
@@ -1589,9 +1589,9 @@
 0000a158 True  long   False  BR24    False     1 (__TEXT,__text)
 0000a14c True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
 0000a138 False long   n/a    LO16DIF True      0x00025ef0
-         False long   n/a    PAIR    True      0x0000a0d8 other_half = 0x0001 
+         False long   n/a    PAIR    True      0x0000a0d8 other_half = 0x0000 
 0000a134 False long   n/a    HA16DIF True      0x00025ef0
-         False long   n/a    PAIR    True      0x0000a0d8 other_half = 0xbe18 
+         False long   n/a    PAIR    True      0x0000a0d8 other_half = 0x1be18 
 0000a12c True  long   False  BR24    False     1 (__TEXT,__text)
 0000a120 True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
 0000a094 True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
@@ -1603,14 +1603,14 @@
 00009f5c True  long   False  BR24    False     1 (__TEXT,__text)
 00009f1c True  long   False  BR24    False     1 (__TEXT,__text)
 00009ed4 False long   n/a    LO16DIF True      0x00025f40
-         False long   n/a    PAIR    True      0x00009eb8 other_half = 0x0001 
+         False long   n/a    PAIR    True      0x00009eb8 other_half = 0x0000 
 00009ed0 False long   n/a    HA16DIF True      0x00025f40
-         False long   n/a    PAIR    True      0x00009eb8 other_half = 0xc088 
+         False long   n/a    PAIR    True      0x00009eb8 other_half = 0x1c088 
 00009ec8 True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
 00009e74 False long   n/a    LO16DIF True      0x00025f20
-         False long   n/a    PAIR    True      0x00009e58 other_half = 0x0001 
+         False long   n/a    PAIR    True      0x00009e58 other_half = 0x0000 
 00009e70 False long   n/a    HA16DIF True      0x00025f20
-         False long   n/a    PAIR    True      0x00009e58 other_half = 0xc0c8 
+         False long   n/a    PAIR    True      0x00009e58 other_half = 0x1c0c8 
 00009e68 True  long   False  BR24    False     1 (__TEXT,__text)
 00009e1c True  long   False  BR24    False     1 (__TEXT,__text)
 00009dd0 True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
@@ -1621,9 +1621,9 @@
 00009c4c True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
 00009c3c True  long   False  BR24    False     3 (__TEXT,__picsymbolstub1)
 00009c20 False long   n/a    LO16DIF True      0x0002545d
-         False long   n/a    PAIR    True      0x00009bd8 other_half = 0x0001 
+         False long   n/a    PAIR    True      0x00009bd8 other_half = 0x0000 
 00009c14 False long   n/a    HA16DIF True      0x0002545d
-         False long   n/a    PAIR    True      0x00009bd8 other_half = 0xb885 
+         False long   n/a    PAIR    True      0x00009bd8 other_half = 0x1b885 
 00009b94 True  long   False  BR24    False     1 (__TEXT,__text)
 00009b2c True  long   False  BR24    False     1 (__TEXT,__text)
 00009a90 True  long   False  BR24    False     1 (__TEXT,__text)

... and so forth ...

I think this indicates what needs to be fixed in the PAIR entries.

llvmbot commented 11 years ago
[fangism:gcc40-stage2-build/lib/Support] fang% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -DLLVMSupport_EXPORTS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-common -no-integrated-as -fvisibility-inlines-hidden -fno-rtti -fPIC -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Support -I/Users/fang/local/src/LLVM-svn/llvm/lib/Support -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/include -I/Users/fang/local/src/LLVM-svn/llvm/include -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fno-exceptions -o CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o -c /Users/fang/local/src/LLVM-svn/llvm/lib/Support/CommandLine.cpp -save-temps
[fangism:gcc40-stage2-build/lib/Support] fang% echo $?
0

But fails with -O1:

[fangism:gcc40-stage2-build/lib/Support] fang% /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -DLLVMSupport_EXPORTS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-common -no-integrated-as -fvisibility-inlines-hidden -fno-rtti -O1 -fPIC -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Support -I/Users/fang/local/src/LLVM-svn/llvm/lib/Support -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/include -I/Users/fang/local/src/LLVM-svn/llvm/include -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fno-exceptions -o CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o -c /Users/fang/local/src/LLVM-svn/llvm/lib/Support/CommandLine.cpp -save-temps
CommandLine.s:22284:non-relocatable subtraction expression, "__ZTVN4llvm11raw_ostreamE" minus "L847$pb"
CommandLine.s:22284:symbol: "__ZTVN4llvm11raw_ostreamE" can't be undefined in a subtraction expression
CommandLine.s:22283:non-relocatable subtraction expression, "__ZTVN4llvm11raw_ostreamE" minus "L847$pb"
CommandLine.s:22283:symbol: "__ZTVN4llvm11raw_ostreamE" can't be undefined in a subtraction expression
CommandLine.s:22258:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L846$pb"
CommandLine.s:22258:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression
CommandLine.s:22256:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L846$pb"
CommandLine.s:22256:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression
clang-3.1: error: assembler command failed with exit code 1 (use -v to see invocation)

One of the optimizations at the -O1 level is producing bad/incomplete assembly.

llvmbot commented 11 years ago

When I remove -O2 from the command-line options, the problem goes away, compilation succeeds! I would very much like to have a stage2,3 build using -O2, so I will still pursue this bug. The test case is delta-reducing on CommandLine.cpp now (keeping -O2)... this will take a while on my old machine.

llvmbot commented 11 years ago

With current svn-trunk r176996 and on my powerpc-darwin8 branch, I still see the same problem in the emitted assembly:

__ZTVN4llvm18raw_string_ostreamE

is never declared as a symbol anywhere in the CommandLine.s. Yet, other __ZTV symbols are emitted. (Again, this is using -no-integrated-as.) I can't use -integrated-as because the C++ headers have some inline asm buried in their headers, and PPC's AsmParser is still on the way. Even then, the symbol emission must be missing in the assembly representation in llvm/MC.

I need to somehow reduce a test case... (delta?)

llvmbot commented 11 years ago

As mentioned in bug 14579 (comment 7), the EmitRawText error message comes from trying to emit a bcl instruction directly. The workaround for that was to use a plain bl instruction. That allowed the tools/clang/test/CodeGenCXX/vtable-debug-info.cpp test to pass (for the first time).

llvmbot commented 11 years ago

So I don't think the stage2 build-fail issue and the vtable-debug-info test failure are the same issue. In the stage 2 build, -no-integrated-as is passed, yet the vtable for llvm::raw_string_ostream is just omitted.

In the test failure which runs:

/Users/fang/local/src/LLVM-svn/gcc40-cmake-build/bin/./clang  -c -g /Volumes/Isolde/sources/LLVM-svn/clang/test/CodeGenCXX/vtable-debug-info.cpp -o /dev/null

I can get it work if I change the options to:

/Users/fang/local/src/LLVM-svn/gcc40-cmake-build/bin/./clang  -c -gdwarf2 -no-integrated-as /Volumes/Isolde/sources/LLVM-svn/clang/test/CodeGenCXX/vtable-debug-info.cpp -o /dev/null

as I have been doing for the stage 2 build. So now what needs to be debugged is figuring out why no symbol definition for the vtable was emitted in the stage 2 build.

I created a small test case that does work:

class foo {
public:
virtual void    v1(void);
};

void
foo::v1(void) {
}

int main(int, char*[]) {
foo b;
b.v1();
}

with when compiled with -gdwarf2 -no-integrated-as, the assembly contains the vtable:

.subsections_via_symbols
        .section        __DATA,__const
        .globl  __ZTV3foo               ; @&#8203;_ZTV3foo
        .align  2
__ZTV3foo:
        .long   0
        .long   __ZTI3foo
        .long   __ZN3foo2v1Ev

        .section        __TEXT,__const
        .globl  __ZTS3foo               ; @&#8203;_ZTS3foo
__ZTS3foo:
        .asciz   "3foo"

        .section        __DATA,__const
        .globl  __ZTI3foo               ; @&#8203;_ZTI3foo
        .align  3
__ZTI3foo:
        .long   __ZTVN10__cxxabiv117__class_type_infoE+8
        .long   __ZTS3foo

so I don't think vtable generation is broken or missing. It just some how got dropped during a bigger compile...

llvmbot commented 11 years ago

The error is complaining about a missing vtable symbol:

__ZTVN4llvm18raw_string_ostreamE
% echo __ZTVN4llvm18raw_string_ostreamE | c++filt 
vtable for llvm::raw_string_ostream

I also noticed there is one failing clang test related to vtable:

********************
Failing Tests (11):
    Clang :: ARCMT/objcmt-numeric-literals.m
    Clang :: CodeGenCXX/vtable-debug-info.cpp   <--- THIS ONE
    Clang :: Driver/output-file-cleanup.c
    Clang :: Frontend/dependency-gen.c
    Clang :: Frontend/verify.c
    Clang :: Index/crash-recovery-modules.m
    Clang :: PCH/cocoa.m
    Clang :: PCH/headersearch.cpp
    Clang :: SemaObjC/cocoa.m
    Clang :: Tooling/auto-detect-from-source-parent-of-cwd.cpp
    Clang :: Tooling/clang-check-pwd.cpp

FAIL: Clang :: CodeGenCXX/vtable-debug-info.cpp (2073 of 5691)
******************** TEST 'Clang :: CodeGenCXX/vtable-debug-info.cpp' FAILED ***
*****************
Script:
--
gtimeout 5m   /Users/fang/local/src/LLVM-svn/gcc40-cmake-build/bin/./clang  -c -
g /Volumes/Isolde/sources/LLVM-svn/clang/test/CodeGenCXX/vtable-debug-info.cpp -
o /dev/null
--
Exit Code: 254
Command Output (stderr):
--
EmitRawText called on an MCStreamer that doesn't support it,  something must not
 be fully mc'ized
Stack dump:
0.      Program arguments: /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/cla
ng-3.1 -cc1 -triple powerpc-apple-macosx10.4.0 -emit-obj -mrelax-all -disable-fr
ee -main-file-name vtable-debug-info.cpp -mrelocation-model pic -pic-level 2 -md
isable-fp-elim -masm-verbose -g -coverage-file /dev/null -resource-dir /Volumes/
Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -fmodule-cache-path /v
ar/tmp/clang-module-cache -fdeprecated-macro -fdebug-compilation-dir /Volumes/Is
olde/builds/LLVM/gcc40-cmake-build/tools/clang/test/CodeGenCXX -ferror-limit 19 
-fmessage-length 0 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runt
ime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-s
ignature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o /dev/null -x
 c++ /Volumes/Isolde/sources/LLVM-svn/clang/test/CodeGenCXX/vtable-debug-info.cp
p 
1.      <eof> parser at end of file
2.      Code generation
clang-3: error: unable to execute command: Trace/BPT trap
clang-3: error: clang frontend command failed due to signal (use -v to see invoc
ation)
clang version 3.3 (trunk)
Target: powerpc-apple-darwin8.11.0
Thread model: posix
clang-3: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bug
s/ and include the crash backtrace, preprocessed source, and associated run scri
pt.
clang-3: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3: note: diagnostic msg: /tmp/vtable-debug-info-a64uvH.cpp
clang-3: note: diagnostic msg: /tmp/vtable-debug-info-a64uvH.sh
clang-3: note: diagnostic msg: 

********************
--

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

Does this explain the undefined symbol __ZTVN4llvm18raw_string_ostreamE ?

llvmbot commented 11 years ago

Example of CommandLine.s (from -save-temps):

__ZNK4llvm2cl6parserIbE15printOptionDiffERKNS0_6OptionEbNS0_11OptionValueIbEEm: ; @_ZNK4llvm2cl6parserIbE15printOptionDiffERKNS0_6OptionEbNS0_11OptionValueIbEEm
; BB#0:                                 ; %entry
        mflr r0
        stw r31, -4(r1)
        stw r0, 8(r1)
        stwu r1, -128(r1)
        mr r31, r1
        stw r29, 108(r31)               ; 4-byte Folded Spill
        stw r30, 104(r31)               ; 4-byte Folded Spill
        stw r26, 120(r31)               ; 4-byte Folded Spill
        stw r27, 116(r31)               ; 4-byte Folded Spill
        stw r28, 112(r31)               ; 4-byte Folded Spill
        mr r29, r5
        mfcr r2                         ; cr2
        mr r5, r7
        mr r30, r6
        rlwinm r2, r2, 8, 0, 31
        stw r2, 100(r31)
        bl L88$pb
L88$pb:
        mflr r26
        bl __ZNK4llvm2cl17basic_parser_impl15printOptionNameERKNS0_6OptionEm
        addis r27, r26, ha16(L__ZNSs4_Rep20_S_empty_rep_storageE$non_lazy_ptr-L88$pb)
        li r4, 1
        addi r28, r31, 64
        lwz r3, lo16(L__ZNSs4_Rep20_S_empty_rep_storageE$non_lazy_ptr-L88$pb)(r27)
        stw r4, 80(r31)
        addis r4, r26, ha16(__ZTVN4llvm18raw_string_ostreamE-L88$pb)
        la r4, lo16(__ZTVN4llvm18raw_string_ostreamE-L88$pb)(r4)
...
llvmbot commented 2 months ago

@llvm/issue-subscribers-backend-powerpc

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [14579](https://llvm.org/bz14579) | | Version | trunk | | OS | MacOS X | | Reporter | LLVM Bugzilla Contributor | | CC | @hfinkel,@iains,@isanbard | ## Extended Description from bug 14387 (originally about .line directives in asm): I built r169799 on powerpc-darwin8, and started a stage 2 build using `-gdwarf2 -no-integrated-as`. ``` [ 0%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o cd /Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Support && /Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build/bin/clang++ -DLLVMSupport_EXPORTS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-common -no-integrated-as -fPIC -fvisibility-inlines-hidden -fno-rtti -O2 -gdwarf2 -fPIC -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/lib/Support -I/Users/fang/local/src/LLVM-svn/llvm/lib/Support -I/Users/fang/local/src/LLVM-svn/gcc40-stage2-build/include -I/Users/fang/local/src/LLVM-svn/llvm/include -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fno-exceptions -o CMakeFiles/LLVMSupport.dir/CommandLine.cpp.o -c /Users/fang/local/src/LLVM-svn/llvm/lib/Support/CommandLine.cpp clang-3: warning: argument unused during compilation: '-gdwarf2' /tmp/CommandLine-qnrm7J.s:11052:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L95$pb" /tmp/CommandLine-qnrm7J.s:11052:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression /tmp/CommandLine-qnrm7J.s:11051:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L95$pb" /tmp/CommandLine-qnrm7J.s:11051:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression /tmp/CommandLine-qnrm7J.s:10812:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L94$pb" /tmp/CommandLine-qnrm7J.s:10812:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression /tmp/CommandLine-qnrm7J.s:10811:non-relocatable subtraction expression, "__ZTVN4llvm18raw_string_ostreamE" minus "L94$pb" /tmp/CommandLine-qnrm7J.s:10811:symbol: "__ZTVN4llvm18raw_string_ostreamE" can't be undefined in a subtraction expression ``` Apparently, `llvm::raw_string_ostream` is unimplemented (MC) for powerpc-darwin8.
chenzheng1030 commented 2 months ago

powerpc-darwin support was dropped long time ago. I don't think there is any work for this.