Bug 295427 - building i386 support with clang on darwin11 requires -new_linker linker option
Summary: building i386 support with clang on darwin11 requires -new_linker linker option
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Fink Packages macOS
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-06 17:15 UTC by Jack Howarth
Modified: 2012-08-19 14:57 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to make Valgrind build with Clang on OSX (524 bytes, patch)
2012-05-25 17:04 UTC, Christoph Erhardt
Details
Fix detection of clang when ccache is used (518 bytes, patch)
2012-08-19 14:57 UTC, Rainer Mueller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Howarth 2012-03-06 17:15:17 UTC
User-Agent:       Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7
Build Identifier: 

When building valgrind (either 3.7.0 or svn) using the clang compilers from Xcode 4.3 on darwin11, the i386 linkages fail as...


../coregrind/link_tool_exe_darwin 0x38000000 clang  -Wno-long-long  -Wno-pointer-sign -fno-stack-protector   -o memcheck-x86-darwin  -arch i386 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wno-format-zero-length -fno-strict-aliasing -fno-builtin -mmacosx-version-min=10.5 -fno-stack-protector -fno-pic -fno-PIC -O2 -nodefaultlibs -nostartfiles -Wl,-u,__start -Wl,-e,__start -arch i386 memcheck_x86_darwin-mc_leakcheck.o memcheck_x86_darwin-mc_malloc_wrappers.o memcheck_x86_darwin-mc_main.o memcheck_x86_darwin-mc_translate.o memcheck_x86_darwin-mc_machine.o memcheck_x86_darwin-mc_errors.o ../coregrind/libcoregrind-x86-darwin.a ../VEX/libvex-x86-darwin.a -lgcc 
link_tool_exe_darwin: /usr/bin/ld -static -arch i386 -macosx_version_min 10.5 -o memcheck-x86-darwin -u __start -e __start -image_base 0x38000000 -stack_addr 0x34000000 -stack_size 0x800000 memcheck_x86_darwin-mc_leakcheck.o memcheck_x86_darwin-mc_malloc_wrappers.o memcheck_x86_darwin-mc_main.o memcheck_x86_darwin-mc_translate.o memcheck_x86_darwin-mc_machine.o memcheck_x86_darwin-mc_errors.o ../coregrind/libcoregrind-x86-darwin.a ../VEX/libvex-x86-darwin.a
/usr/bin/ld_classic: memcheck_x86_darwin-mc_leakcheck.o incompatible, file contains unsupported type of section 19 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: memcheck_x86_darwin-mc_malloc_wrappers.o incompatible, file contains unsupported type of section 19 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: memcheck_x86_darwin-mc_main.o incompatible, file contains unsupported type of section 20 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: memcheck_x86_darwin-mc_translate.o incompatible, file contains unsupported type of section 17 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: warning memcheck_x86_darwin-mc_machine.o could not understand DWARF debug information
/usr/bin/ld_classic: memcheck_x86_darwin-mc_errors.o incompatible, file contains unsupported type of section 18 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: ../VEX/libvex-x86-darwin.a(libvex_x86_darwin_a-ir_defs.o) incompatible, file contains unsupported type of section 18 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)


Reproducible: Always

Steps to Reproduce:
1. Execute...
setenv CC clang
setenv CCX clang++
../valgrind/configure --prefix=/Users/howarth/valgrind_dist --without-mpicc
make

...under darwin11 with Xcode 4.3 installed.
Actual Results:  
../coregrind/link_tool_exe_darwin 0x38000000 clang  -Wno-long-long  -Wno-pointer-sign -fno-stack-protector   -o memcheck-x86-darwin  -arch i386 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wno-format-zero-length -fno-strict-aliasing -fno-builtin -mmacosx-version-min=10.5 -fno-stack-protector -fno-pic -fno-PIC -O2 -nodefaultlibs -nostartfiles -Wl,-u,__start -Wl,-e,__start -arch i386 memcheck_x86_darwin-mc_leakcheck.o memcheck_x86_darwin-mc_malloc_wrappers.o memcheck_x86_darwin-mc_main.o memcheck_x86_darwin-mc_translate.o memcheck_x86_darwin-mc_machine.o memcheck_x86_darwin-mc_errors.o ../coregrind/libcoregrind-x86-darwin.a ../VEX/libvex-x86-darwin.a -lgcc 
link_tool_exe_darwin: /usr/bin/ld -static -arch i386 -macosx_version_min 10.5 -o memcheck-x86-darwin -u __start -e __start -image_base 0x38000000 -stack_addr 0x34000000 -stack_size 0x800000 memcheck_x86_darwin-mc_leakcheck.o memcheck_x86_darwin-mc_malloc_wrappers.o memcheck_x86_darwin-mc_main.o memcheck_x86_darwin-mc_translate.o memcheck_x86_darwin-mc_machine.o memcheck_x86_darwin-mc_errors.o ../coregrind/libcoregrind-x86-darwin.a ../VEX/libvex-x86-darwin.a
/usr/bin/ld_classic: memcheck_x86_darwin-mc_leakcheck.o incompatible, file contains unsupported type of section 19 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: memcheck_x86_darwin-mc_malloc_wrappers.o incompatible, file contains unsupported type of section 19 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: memcheck_x86_darwin-mc_main.o incompatible, file contains unsupported type of section 20 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: memcheck_x86_darwin-mc_translate.o incompatible, file contains unsupported type of section 17 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: warning memcheck_x86_darwin-mc_machine.o could not understand DWARF debug information
/usr/bin/ld_classic: memcheck_x86_darwin-mc_errors.o incompatible, file contains unsupported type of section 18 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)
/usr/bin/ld_classic: ../VEX/libvex-x86-darwin.a(libvex_x86_darwin_a-ir_defs.o) incompatible, file contains unsupported type of section 18 (__IMPORT,__pointers) in load command 0 (must specify "-dynamic" to be used)

Expected Results:  
I expected the linkage of the i386 static executables to succeed without errors.

The darwin linker developer at Apple says we need to use the -new_linker linker option with i386 code on clang in this instance. That patch to achieve this is...


Index: coregrind/link_tool_exe_darwin.in
===================================================================
--- coregrind/link_tool_exe_darwin.in	(revision 12418)
+++ coregrind/link_tool_exe_darwin.in	(working copy)
@@ -139,7 +139,7 @@ die "Can't find '-arch archstr' in comma
 # build the command line
 my $cmd = "/usr/bin/ld";
 
-$cmd = "$cmd -static";
+$cmd = "$cmd -static -new_linker";
 $cmd = "$cmd -arch $archstr";
 $cmd = "$cmd -macosx_version_min 10.5";
 $cmd = "$cmd -o $outname";
Comment 1 Julian Seward 2012-03-07 17:09:11 UTC
> -$cmd = "$cmd -static";
> +$cmd = "$cmd -static -new_linker";

This is going to need a configure test (or some other way of applying
it only in certain circumstances.)  I tried it just now on OSX 10.7
with Xcode 4.1 and the 32-bit tool executables segfault at startup
with it.  64-bit ones are OK.
Comment 2 Jack Howarth 2012-03-08 00:09:51 UTC
(In reply to comment #1)
> > -$cmd = "$cmd -static";
> > +$cmd = "$cmd -static -new_linker";
> 
> This is going to need a configure test (or some other way of applying
> it only in certain circumstances.)  I tried it just now on OSX 10.7
> with Xcode 4.1 and the 32-bit tool executables segfault at startup
> with it.  64-bit ones are OK.

Do you have the patch in https://bugs.kde.org/show_bug.cgi?id=295428 properly applied? The i386 static executables built with clang will segfault without that fix.
I just tested a build of valgrind 3.7.0 using clang and -new_linker  and all of the i386 static executables run fine. The same is true when using llvm-gcc-4.2 from Xcode 4.2 and -new_linker. These tests were done on darwin10.
Comment 3 Christoph Erhardt 2012-05-25 17:04:01 UTC
Created attachment 71366 [details]
Patch to make Valgrind build with Clang on OSX

Here's a patch to add "-new_linker" to the linker flags if @CC@ either ends with "clang" or is a symlink to a file that ends with "clang". I hope this is the correct criterion - I adopted the basic idea from the Fink project (http://fink.cvs.sourceforge.net/fink/dists/10.7/stable/main/finkinfo/devel/valgrind.info?view=markup).
Comment 4 Julian Seward 2012-07-20 16:48:05 UTC
(In reply to comment #3)
> Created attachment 71366 [details]
> Patch to make Valgrind build with Clang on OSX

Committed w/ modifications, r12766.  Thanks.  The change is to use the
C compiler name that is passed to this script as the second arg
instead of looking directly at $CC.
Comment 5 Rainer Mueller 2012-08-19 14:57:42 UTC
Created attachment 73299 [details]
Fix detection of clang when ccache is used

There is still a problem with this method when using ccache for compilation of valgrind. For applying ccache, configure can be run with CC='ccache /usr/bin/clang' and then the perl script would be called like this: ../coregrind/link_tool_exe_darwin 0x138000000 ccache /usr/bin/clang ...

The attached patch adds a check if the second argument is ccache and in this case, the actual path to the compiler is in the next argument.