[hackers] [scc] [driver] Link against our crt, use ld instead of gcc || Quentin Rameau

From: <git_AT_suckless.org>
Date: Fri, 24 Mar 2017 10:34:25 +0100 (CET)

commit 9deeff396080448b6a80cc295ee9b276a727f15a
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Wed Mar 22 16:25:53 2017 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Mar 24 10:12:19 2017 +0100

    [driver] Link against our crt, use ld instead of gcc

diff --git a/Makefile b/Makefile
index 203dd0c..0dffc46 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -76,4 +76,4 @@ clean:
         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
diff --git a/config.mk b/config.mk
index 3b3a1f0..a719ab8 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -24,6 +24,7 @@ AS = as
 
 # for Plan9 add -D_SUSV2_SOURCE
 SCC_CFLAGS = -DARCH=\"$(ARCH)\" \
+ -DSYS=\"$(SYS)\" \
              $(CSTDINC) \
              -DPREFIX=\"$(PREFIX)\" \
              -g \
diff --git a/driver/posix/Makefile b/driver/posix/Makefile
index 6124293..782a0a2 100644
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
_AT_@ -7,7 +7,7 @@ OBJS = scc.o
 
 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 $_AT_
_AT_@ -15,6 +15,9 @@ scc: $(OBJS) ../../lib/libcc.a
 ../../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
 
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index a5d89d5..dd74e26 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -17,6 +17,7 @@ static char sccsid[] = "@(#) ./driver/posix/scc.c";
 #include "../../inc/arg.h"
 #include "../../inc/cc.h"
 #include "../../inc/syslibs.h"
+#include "../../inc/ldflags.h"
 
 enum {
         CC1,
_AT_@ -47,12 +48,12 @@ static struct tool {
         [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;
_AT_@ -98,6 +99,7 @@ static int
 inittool(int tool)
 {
         struct tool *t = &tools[tool];
+ char *crt;
         int n;
 
         if (t->init)
_AT_@ -115,7 +117,8 @@ inittool(int tool)
                         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);
_AT_@ -123,6 +126,14 @@ inittool(int tool)
                         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");
_AT_@ -432,6 +443,8 @@ main(int argc, char *argv[])
 
         if (!(arch = getenv("ARCH")))
                 arch = ARCH;
+ if (!(sys = getenv("SYS")))
+ sys = SYS;
         if (!(execpath = getenv("SCCEXECPATH")))
                 execpath = PREFIX "/libexec/scc";
 
_AT_@ -492,6 +505,9 @@ main(int argc, char *argv[])
         case 's':
                 sflag = 1;
                 break;
+ case 't':
+ sys = EARGF(usage());
+ break;
         case 'W':
                 EARGF(usage());
         case 'w':
_AT_@ -535,6 +551,7 @@ operand:
                 return failure;
 
         if (link && !failure) {
+ addarg(LD, xstrdup("-lc"));
                 spawn(settool(LD, NULL, LAST_TOOL));
                 validatetools();
         }
diff --git a/inc/ldflags.def.h b/inc/ldflags.def.h
new file mode 100644
index 0000000..1a06c2e
--- /dev/null
+++ b/inc/ldflags.def.h
_AT_@ -0,0 +1,6 @@
+char *ldflags[] = {
+ "-static",
+ /* on OpenBSD, disable pie */
+ /* "-nopie", */
+ NULL
+};
Received on Fri Mar 24 2017 - 10:34:25 CET

This archive was generated by hypermail 2.3.0 : Fri Mar 24 2017 - 10:36:34 CET