Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#33207 closed defect (fixed)

clang LTO doesn't work with older ld64

Reported by: mamoll (Mark Moll) Owned by: jeremyhu (Jeremy Huddleston Sequoia)
Priority: Normal Milestone:
Component: ports Version: 2.0.3
Keywords: llvm clang LTO Cc: cooljeanius (Eric Gallager)
Port: clang-3.1

Description

Take the following minimal program called, say, test.cpp:

int main(int,char**) { return 0; }

and compile it with -O4. This is what I see:

clang++-mp-3.1 -O4 test.cpp -o test -v
clang version 3.1 (trunk 149973)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
 "/opt/local/libexec/llvm-3.1/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-llvm-bc -disable-free -main-file-name test.cpp -pic-level 1 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 127.2 -v -resource-dir /opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1 -fmodule-cache-path /var/folders/5x/k48hkr0n2mx5qz3_0xw516800000gn/T/clang-module-cache -I /opt/local/include -O3 -fdeprecated-macro -fdebug-compilation-dir /Users/mmoll/omplapp/build/Release -ferror-limit 19 -fmessage-length 97 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/5x/k48hkr0n2mx5qz3_0xw516800000gn/T/test-HHZUrL.o -x c++ test.cpp
clang -cc1 version 3.1 based upon LLVM 3.1svn default target x86_64-apple-darwin11.3.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/include
 /usr/include/c++/4.2.1
 /usr/include/c++/4.2.1/backward
 /usr/local/include
 /opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin11/4.2.1/ld" -demangle -object_path_lto /var/folders/5x/k48hkr0n2mx5qz3_0xw516800000gn/T/cc-bK5Nhp.o -dynamic -arch x86_64 -macosx_version_min 10.7.0 -o test -lcrt1.10.6.o /var/folders/5x/k48hkr0n2mx5qz3_0xw516800000gn/T/test-HHZUrL.o -lstdc++ -lSystem
ld: in /var/folders/5x/k48hkr0n2mx5qz3_0xw516800000gn/T/test-HHZUrL.o, could not parse object file /var/folders/5x/k48hkr0n2mx5qz3_0xw516800000gn/T/test-HHZUrL.o: Invalid MODULE_CODE_FUNCTION record for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If I explicitly use the LLVM linker I get an executable that can't be run:

> clang++-mp-3.1 -O4 test.cpp -o test.o -c
> llvm-ld-mp-3.1 -o test test.o -lstdc++ -lSystem
> ./test
./test: line 3: exec: lli: not found

Change History (7)

comment:1 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Status: newassigned

I can't reproduce this here because my ld does support LTO.

The second issue is just because you haven't done 'port select llvm', so lli isn't in your $PATH. You can work around that bug with:

LLVMINTERP=lli-mp-3.1 ./test

comment:2 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

LLVMINTERP was fixed with r91154 r91155

comment:3 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Summary: clang-3.1 LTO brokenclang LTO doesn't work with older ld64

comment:4 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

comment:5 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

I can reproduce it by forcing an old libLTO into /usr/lib:

sudo mv /usr/lib/libLTO.dylib /usr/lib/libLTO.dylib.bak
sudo cp /opt/local/libexec/llvm-2.9/lib/libLTO.dylib /usr/lib

clang++-mp-3.1 -O4 test.cpp -c
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.7.0 -o test -lcrt1.10.6.o test.o -lstdc++ -lSystem /opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1/lib/darwin/libclang_rt.osx.a

And I can work around it in either of these ways:

DYLD_LIBRARY_PATH=/opt/local/libexec/llvm-3.1/lib /usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.7.0 -o test -lcrt1.10.6.o test.o -lstdc++ -lSystem /opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1/lib/darwin/libclang_rt.osx.a
cd /opt/local/libexec/llvm-3.0/bin
sudo ln -s /usr/bin/ld
...
/opt/local/libexec/llvm-3.1/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.7.0 -o test -lcrt1.10.6.o test.o -lstdc++ -lSystem /opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1/lib/darwin/libclang_rt.osx.a

comment:6 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Resolution: fixed
Status: assignedclosed

comment:7 Changed 10 years ago by cooljeanius (Eric Gallager)

Cc: egall@… added

Cc Me!

Note: See TracTickets for help on using tickets.