ref: 5ab4d45674cc1e5a82921c1f86cb70593dd0a226
parent: 3fc33c857e20a88b54d6c44b38d5eda753a98bfb
author: Quentin Rameau <quinq@fifth.space>
date: Wed Mar 22 12:25:53 EDT 2017
[driver] Link against our crt, use ld instead of gcc
--- a/Makefile
+++ b/Makefile
@@ -76,4 +76,4 @@
rm -f bin/cc* bin/scc
distclean: clean
- rm -f inc/sysincludes.h inc/syslibs.h
+ rm -f inc/sysincludes.h inc/syslibs.h inc/ldflags.h
--- a/config.mk
+++ b/config.mk
@@ -24,6 +24,7 @@
# for Plan9 add -D_SUSV2_SOURCE
SCC_CFLAGS = -DARCH=\"$(ARCH)\" \
+ -DSYS=\"$(SYS)\" \
$(CSTDINC) \
-DPREFIX=\"$(PREFIX)\" \
-g \
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -7,7 +7,7 @@
all: scc
-$(OBJS): ../../inc/cc.h ../../inc/arg.h ../../inc/syslibs.h
+$(OBJS): ../../inc/cc.h ../../inc/arg.h ../../inc/syslibs.h ../../inc/ldflags.h
scc: $(OBJS) ../../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../../lib/libcc.a -o $@
@@ -14,6 +14,9 @@
../../inc/syslibs.h: ../../inc/syslibs.def.h
cp -f ../../inc/syslibs.def.h ../../inc/syslibs.h
+
+../../inc/ldflags.h: ../../inc/ldflags.def.h
+ cp -f ../../inc/ldflags.def.h ../../inc/ldflags.h
../../lib/libcc.a:
cd ../../lib && $(MAKE) -e
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -17,6 +17,7 @@
#include "../../inc/arg.h"
#include "../../inc/cc.h"
#include "../../inc/syslibs.h"
+#include "../../inc/ldflags.h"
enum {
CC1,
@@ -47,12 +48,12 @@
[QBE] = { .bin = "qbe", .cmd = "qbe", },
[TEEAS] = { .bin = "tee", .cmd = "tee", },
[AS] = { .bin = "as", .cmd = "as", },
- [LD] = { .bin = "gcc", .cmd = "gcc", }, /* TODO use ld */
+ [LD] = { .bin = "ld", .cmd = "ld", },
[STRIP] = { .bin = "strip", .cmd = "strip", },
};
char *argv0;
-static char *arch, *execpath, *objfile, *outfile;
+static char *arch, *sys, *execpath, *objfile, *outfile;
static char *tmpdir;
static size_t tmpdirln;
static struct items objtmp, objout;
@@ -98,6 +99,7 @@
inittool(int tool)
{
struct tool *t = &tools[tool];
+ char *crt;
int n;
if (t->init)
@@ -115,7 +117,8 @@
die("scc: target tool path too long");
break;
case LD:
- addarg(tool, "-no-pie");
+ for (n = 0; ldflags[n]; ++n)
+ addarg(tool, ldflags[n]);
addarg(tool, "-o");
t->outfile = outfile ? outfile : xstrdup("a.out");
addarg(tool, t->outfile);
@@ -123,6 +126,14 @@
addarg(tool, "-L");
addarg(tool, syslibs[n]);
}
+ n = snprintf(NULL, 0, "%s-%s-%s.o",
+ PREFIX "/lib/scc/crt", arch, sys);
+ if (n < 0)
+ die("scc: wrong crt file name");
+ crt = xmalloc(++n);
+ n = snprintf(crt, n, "%s-%s-%s.o",
+ PREFIX "/lib/scc/crt", arch, sys);
+ addarg(tool, crt);
break;
case AS:
addarg(tool, "-o");
@@ -432,6 +443,8 @@
if (!(arch = getenv("ARCH")))
arch = ARCH;
+ if (!(sys = getenv("SYS")))
+ sys = SYS;
if (!(execpath = getenv("SCCEXECPATH")))
execpath = PREFIX "/libexec/scc";
@@ -492,6 +505,9 @@
case 's':
sflag = 1;
break;
+ case 't':
+ sys = EARGF(usage());
+ break;
case 'W':
EARGF(usage());
case 'w':
@@ -535,6 +551,7 @@
return failure;
if (link && !failure) {
+ addarg(LD, xstrdup("-lc"));
spawn(settool(LD, NULL, LAST_TOOL));
validatetools();
}
--- /dev/null
+++ b/inc/ldflags.def.h
@@ -1,0 +1,6 @@
+char *ldflags[] = {
+ "-static",
+ /* on OpenBSD, disable pie */
+ /* "-nopie", */
+ NULL
+};