ref: 5269edd399f1b55f98e10fc5e809e22bec6c7bb1
parent: f15c3cc3fc96cc9cd383f53d6dd662bfb835a1b2
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Mar 10 14:43:20 EST 2016
Fix build on OSX, by deduping syms correctly. With macho, we need to set a different attribute for asm than we need on ELF targets.
--- a/6/asm.h
+++ b/6/asm.h
@@ -53,7 +53,8 @@
} Rclass;
typedef enum {
- Gnugas,
+ Gnugaself,
+ Gnugasmacho,
Plan9,
} Asmsyntax;
--- a/6/gen.c
+++ b/6/gen.c
@@ -152,8 +152,12 @@
void gen(Node *file, char *out)
{
switch (asmsyntax) {
- case Plan9: genp9(file, out); break;
- case Gnugas: gengas(file, out); break;
- default: die("unknown target"); break;
+ case Plan9:
+ genp9(file, out); break;
+ case Gnugaself:
+ case Gnugasmacho:
+ gengas(file, out); break;
+ default:
+ die("unknown target"); break;
}
}
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -297,6 +297,19 @@
}
}
+static void emitonce(FILE *fd, Blob *b)
+{
+ if (asmsyntax == Gnugaself) {
+ fprintf(fd, ".section .text.%s%s,\"aG\",%s%s,comdat\n",
+ Symprefix, b->lbl, Symprefix, b->lbl);
+ } else if (asmsyntax == Gnugasmacho) {
+ if (b->isglobl)
+ fprintf(fd, ".weak_def_can_be_hidden %s%s\n", Symprefix, b->lbl);
+ } else {
+ die("Unknown asm flavor");
+ }
+}
+
static void writeblob(FILE *fd, Blob *b)
{
size_t i;
@@ -305,7 +318,7 @@
return;
if (b->lbl) {
if (b->iscomdat)
- fprintf(fd, ".section .text.%s%s,\"aG\",%s%s,comdat\n", Symprefix, b->lbl, Symprefix, b->lbl);
+ emitonce(fd, b);
if (b->isglobl)
fprintf(fd, ".globl %s%s\n", Symprefix, b->lbl);
fprintf(fd, "%s%s:\n", Symprefix, b->lbl);
--- a/6/main.c
+++ b/6/main.c
@@ -165,7 +165,7 @@
outfile = NULL;
- optinit(&ctx, "cd:?hSo:I:9G", argv, argc);
+ optinit(&ctx, "cd:?hSo:I:9G:", argv, argc);
asmsyntax = Defaultasm;
while (!optdone(&ctx)) {
switch (optnext(&ctx)) {
@@ -191,7 +191,12 @@
asmsyntax = Plan9;
break;
case 'G':
- asmsyntax = Gnugas;
+ if (!strcmp(ctx.optarg, "e"))
+ asmsyntax = Gnugaself;
+ else if (!strcmp(ctx.optarg, "m"))
+ asmsyntax = Gnugasmacho;
+ else
+ die("unknown gnu syntax flavor");
break;
case 'I':
lappend(&incpaths, &nincpaths, ctx.optarg);
--- a/configure
+++ b/configure
@@ -40,7 +40,6 @@
echo '#define Instroot "'$prefix'"' > config.h
echo '#define Asmcmd {"as", "-g", "-o", NULL}' >> config.h
-echo '#define Defaultasm Gnugas' >> config.h
echo '#define Objsuffix ".o"' >> config.h
echo 'export SYSCLASS=posixy' >> config.mk
@@ -60,7 +59,7 @@
case $OS in
*Linux*)
echo '#define Symprefix ""' >> config.h
- echo '#define Defaultasm Gnugas' >> config.h
+ echo '#define Defaultasm Gnugaself' >> config.h
echo 'export SYS=linux' >> config.mk
echo 'const Sys = "Linux"' >> mbld/config.myr
echo 'const Linkcmd = ["ld", "-o"]' >> mbld/config.myr
@@ -67,6 +66,7 @@
;;
*Darwin*)
echo '#define Symprefix "_"' >> config.h
+ echo '#define Defaultasm Gnugasmacho' >> config.h
echo 'export SYS=osx' >> config.mk
echo 'const Linkcmd = ["ld", ' \
'"-pagezero_size", "0x100000000",' \
@@ -76,7 +76,7 @@
;;
*FreeBSD*)
echo '#define Symprefix ""' >> config.h
- echo '#define Defaultasm Gnugas' >> config.h
+ echo '#define Defaultasm Gnugaself' >> config.h
echo 'export SYS=freebsd' >> config.mk
echo 'const Linkcmd = ["ld", "-o"]' >> mbld/config.myr
echo 'const Sys = "FreeBSD"' >> mbld/config.myr