ref: da9b38c75c11cc7f18415849b5bf14579ef8317c
parent: bd178b6dc6a6d6a81be05c0a1f7c03b352f833c1
author: cinap_lenrek <[email protected]>
date: Sat Mar 18 23:05:24 EDT 2017
5l,6l,8l,kl,ql,vl: allow duplicate GLOBAL symbols (from Ori Bernstein) The plan 9 assemblers support the DUPOK flag on text symbols. They parse and ignore it on GLOBL symbols. This patch makes it work in the linkers. The reason I ran into this is because my programming language (Myrddin) uses data symbols to generate type information, and it's useful to avoid duplicating all of the type info in every file that gets generated.
--- a/sys/src/cmd/5l/asm.c
+++ b/sys/src/cmd/5l/asm.c
@@ -578,7 +578,7 @@
}
if(l >= n)
continue;
- if(p->as != AINIT && p->as != ADYNT) {
+ if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
print("%P\n", p);
--- a/sys/src/cmd/5l/l.h
+++ b/sys/src/cmd/5l/l.h
@@ -82,6 +82,7 @@
short become;
short frame;
uchar subtype;
+ char dupok;
ushort file;
long value;
long sig;
--- a/sys/src/cmd/5l/obj.c
+++ b/sys/src/cmd/5l/obj.c
@@ -868,6 +868,8 @@
diag("GLOBL must have a name\n%P", p);
errorexit();
}
+ if(p->reg & DUPOK)
+ s->dupok = 1;
if(s->type == 0 || s->type == SXREF) {
s->type = SBSS;
s->value = 0;
@@ -1113,6 +1115,7 @@
s->version = v;
s->value = 0;
s->sig = 0;
+ s->dupok = 0;
hash[h] = s;
return s;
}
--- a/sys/src/cmd/6l/asm.c
+++ b/sys/src/cmd/6l/asm.c
@@ -316,7 +316,7 @@
}
if(l >= n)
continue;
- if(p->as != AINIT && p->as != ADYNT) {
+ if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
print("%P\n", p);
--- a/sys/src/cmd/6l/l.h
+++ b/sys/src/cmd/6l/l.h
@@ -79,6 +79,7 @@
short version;
short become;
short frame;
+ char dupok;
uchar subtype;
ushort file;
vlong value;
--- a/sys/src/cmd/6l/list.c
+++ b/sys/src/cmd/6l/list.c
@@ -23,6 +23,7 @@
bigP = p;
switch(p->as) {
case ATEXT:
+ case AGLOBL:
if(p->from.scale) {
snprint(str, sizeof str, "(%ld) %A %D,%d,%D",
p->line, p->as, &p->from, p->from.scale, &p->to);
--- a/sys/src/cmd/6l/obj.c
+++ b/sys/src/cmd/6l/obj.c
@@ -899,10 +899,13 @@
case AGLOBL:
s = p->from.sym;
+ if(p->from.scale & DUPOK)
+ s->dupok = 1;
if(s->type == 0 || s->type == SXREF) {
s->type = SBSS;
s->value = 0;
}
+
if(s->type != SBSS) {
diag("%s: redefinition: %s in %s",
pn, s->name, TNAME);
@@ -1158,6 +1161,7 @@
s->version = v;
s->value = 0;
s->sig = 0;
+ s->dupok = 0;
hash[h] = s;
nsymbol++;
return s;
--- a/sys/src/cmd/8l/asm.c
+++ b/sys/src/cmd/8l/asm.c
@@ -421,7 +421,7 @@
}
if(l >= n)
continue;
- if(p->as != AINIT && p->as != ADYNT) {
+ if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
print("%P\n", p);
--- a/sys/src/cmd/8l/l.h
+++ b/sys/src/cmd/8l/l.h
@@ -80,6 +80,7 @@
short become;
short frame;
uchar subtype;
+ char dupok;
ushort file;
long value;
long sig;
--- a/sys/src/cmd/8l/list.c
+++ b/sys/src/cmd/8l/list.c
@@ -23,6 +23,7 @@
bigP = p;
switch(p->as) {
case ATEXT:
+ case AGLOBL:
if(p->from.scale) {
snprint(str, sizeof(str), "(%ld) %A %D,%d,%D",
p->line, p->as, &p->from, p->from.scale, &p->to);
--- a/sys/src/cmd/8l/obj.c
+++ b/sys/src/cmd/8l/obj.c
@@ -885,6 +885,8 @@
case AGLOBL:
s = p->from.sym;
+ if(p->from.scale & DUPOK)
+ s->dupok = 1;
if(s->type == 0 || s->type == SXREF) {
s->type = SBSS;
s->value = 0;
@@ -1134,6 +1136,7 @@
s->version = v;
s->value = 0;
s->sig = 0;
+ s->dupok = 0;
hash[h] = s;
nsymbol++;
return s;
--- a/sys/src/cmd/kl/asm.c
+++ b/sys/src/cmd/kl/asm.c
@@ -396,7 +396,7 @@
}
if(l >= n)
continue;
- if(p->as != AINIT && p->as != ADYNT) {
+ if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
print("%P\n", p);
--- a/sys/src/cmd/kl/l.h
+++ b/sys/src/cmd/kl/l.h
@@ -65,6 +65,7 @@
short version;
short become;
short frame;
+ char dupok;
long value;
Sym *link;
};
--- a/sys/src/cmd/kl/obj.c
+++ b/sys/src/cmd/kl/obj.c
@@ -737,6 +737,8 @@
diag("GLOBL must have a name\n%P", p);
errorexit();
}
+ if(p->reg & DUPOK)
+ s->dupok = 1;
if(s->type == 0 || s->type == SXREF) {
s->type = SBSS;
s->value = 0;
@@ -951,6 +953,7 @@
s->type = 0;
s->version = v;
s->value = 0;
+ s->dupok = 0;
hash[h] = s;
return s;
}
--- a/sys/src/cmd/ql/asm.c
+++ b/sys/src/cmd/ql/asm.c
@@ -756,7 +756,7 @@
}
if(l >= n)
continue;
- if(p->as != AINIT && p->as != ADYNT) {
+ if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
print("%P\n", p);
--- a/sys/src/cmd/ql/l.h
+++ b/sys/src/cmd/ql/l.h
@@ -61,6 +61,7 @@
short become;
short frame;
uchar subtype;
+ char dupok;
ushort file;
long value;
long sig;
--- a/sys/src/cmd/ql/obj.c
+++ b/sys/src/cmd/ql/obj.c
@@ -849,6 +849,8 @@
diag("GLOBL must have a name\n%P", p);
errorexit();
}
+ if(p->reg & DUPOK)
+ s->dupok = 1;
if(s->type == 0 || s->type == SXREF) {
s->type = SBSS;
s->value = 0;
@@ -1085,6 +1087,7 @@
s->version = v;
s->value = 0;
s->sig = 0;
+ s->dupok = 0;
hash[h] = s;
return s;
}
--- a/sys/src/cmd/vl/asm.c
+++ b/sys/src/cmd/vl/asm.c
@@ -708,7 +708,7 @@
}
if(l >= n)
continue;
- if(p->as != AINIT && p->as != ADYNT) {
+ if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
print("%P\n", p);
--- a/sys/src/cmd/vl/l.h
+++ b/sys/src/cmd/vl/l.h
@@ -74,6 +74,7 @@
short version;
short become;
short frame;
+ char dupok;
long value;
Sym* link;
};
--- a/sys/src/cmd/vl/obj.c
+++ b/sys/src/cmd/vl/obj.c
@@ -803,6 +803,8 @@
diag("GLOBL must have a name\n%P", p);
errorexit();
}
+ if (p->reg & DUPOK)
+ s->dupok = 1;
if(s->type == 0 || s->type == SXREF) {
s->type = SBSS;
s->value = 0;
@@ -1036,6 +1038,7 @@
s->type = 0;
s->version = v;
s->value = 0;
+ s->dupok = 0;
hash[h] = s;
return s;
}