[cfe-commits] patch to link libgcc on OpenBSD
Jonathan Gray
jsg at goblin.cx
Sun Aug 2 06:28:19 PDT 2009
This diff adds libgcc parts of the ld command line for OpenBSD, and tweaks
a few other things to match what gcc passes to ld more accurately.
Index: test/Driver/openbsd.c
===================================================================
--- test/Driver/openbsd.c (revision 77802)
+++ test/Driver/openbsd.c (working copy)
@@ -1,6 +1,6 @@
// RUN: clang -ccc-clang-archs "" -ccc-host-triple i686-pc-openbsd %s -### 2> %t.log &&
// RUN: grep 'clang-cc" "-triple" "i386-pc-openbsd"' %t.log &&
// RUN: grep 'as" "-o" ".*\.o" ".*\.s' %t.log &&
-// RUN: grep 'ld" "--eh-frame-hdr" "-dynamic-linker" ".*ld.so" "-o" "a\.out" ".*crt0.o" ".*crtbegin.o" ".*\.o" "-lc" ".*crtend.o"' %t.log &&
+// RUN: grep 'ld" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" ".*ld.so" "-o" "a\.out" ".*crt0.o" ".*crtbegin.o" ".*\.o" "-lgcc" "-lc" "-lgcc" ".*crtend.o"' %t.log &&
// RUN: true
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 77802)
+++ lib/Driver/Tools.cpp (working copy)
@@ -1818,12 +1818,19 @@
const Driver &D = getToolChain().getHost().getDriver();
ArgStringList CmdArgs;
+ if ((!Args.hasArg(options::OPT_nostdlib)) &&
+ (!Args.hasArg(options::OPT_shared))) {
+ CmdArgs.push_back("-e");
+ CmdArgs.push_back("__start");
+ }
+
if (Args.hasArg(options::OPT_static)) {
CmdArgs.push_back("-Bstatic");
} else {
CmdArgs.push_back("--eh-frame-hdr");
+ CmdArgs.push_back("-Bdynamic");
if (Args.hasArg(options::OPT_shared)) {
- CmdArgs.push_back("-Bshareable");
+ CmdArgs.push_back("-shared");
} else {
CmdArgs.push_back("-dynamic-linker");
CmdArgs.push_back("/usr/libexec/ld.so");
@@ -1850,6 +1857,10 @@
}
}
+ CmdArgs.push_back(MakeFormattedString(Args,
+ llvm::format("-L/usr/lib/gcc-lib/%s/3.3.5",
+ getToolChain().getTripleString().c_str())));
+
Args.AddAllArgs(CmdArgs, options::OPT_L);
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
Args.AddAllArgs(CmdArgs, options::OPT_e);
@@ -1873,10 +1884,15 @@
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs)) {
+ // FIXME: For some reason GCC passes -lgcc before adding
+ // the default system libraries. Just mimic this for now.
+ CmdArgs.push_back("-lgcc");
if (Args.hasArg(options::OPT_pthread))
CmdArgs.push_back("-pthread");
- CmdArgs.push_back("-lc");
+ if (!Args.hasArg(options::OPT_shared))
+ CmdArgs.push_back("-lc");
+ CmdArgs.push_back("-lgcc");
}
if (!Args.hasArg(options::OPT_nostdlib) &&
More information about the cfe-commits
mailing list