~mpu/qbe

reject multiple visibility definitions for a symbol v1 PROPOSED

Armin Weigl: 2
 reject multiple visibility definitions for a symbol
 add hidden and weak exports

 4 files changed, 32 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mpu/qbe/patches/33483/mbox | git am -3
Learn more about email & git

[PATCH 1/2] reject multiple visibility definitions for a symbol Export this patch

Signed-off-by: Armin Weigl <tb46305@gmail.com>
---
 parse.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parse.c b/parse.c
index 1912c8b..0d47f95 100644
--- a/parse.c
+++ b/parse.c
@@ -1068,6 +1068,8 @@ parselnk(Lnk *lnk)
	for (haslnk=0;; haslnk=1)
		switch ((t=nextnl())) {
		case Texport:
			if (lnk->export)
				err("only one visibility allowed");
			lnk->export = 1;
			break;
		case Tsection:
-- 
2.35.1

[PATCH 2/2] add hidden and weak exports Export this patch

Signed-off-by: Armin Weigl <tb46305@gmail.com>
---
 gas.c        | 11 ++++++++++-
 parse.c      | 21 ++++++++++++++++++---
 tools/lexh.c |  4 ++--
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/gas.c b/gas.c
index 865edba..5e536b6 100644
--- a/gas.c
+++ b/gas.c
@@ -36,8 +36,17 @@ gasemitlnk(char *n, Lnk *l, char *s, FILE *f)
	if (l->align)
		fprintf(f, ".balign %d\n", l->align);
	p = n[0] == '"' ? "" : gassym;
	if (l->export)
	switch (l->export) {
	case 1:
		fprintf(f, ".globl %s%s\n", p, n);
		break;
	case 2:
		fprintf(f, ".hidden %s%s\n", p, n);
		break;
	case 3:
		fprintf(f, ".weak %s%s\n", p, n);
		break;
	}
	fprintf(f, "%s%s:\n", p, n);
}

diff --git a/parse.c b/parse.c
index 0d47f95..40dc9ec 100644
--- a/parse.c
+++ b/parse.c
@@ -38,6 +38,8 @@ enum {
	Tjnz,
	Tret,
	Texport,
	Thidden,
	Tweak,
	Tfunc,
	Ttype,
	Tdata,
@@ -88,6 +90,8 @@ static char *kwmap[Ntok] = {
	[Tjnz] = "jnz",
	[Tret] = "ret",
	[Texport] = "export",
	[Thidden] = "hidden",
	[Tweak] = "weak",
	[Tfunc] = "function",
	[Ttype] = "type",
	[Tdata] = "data",
@@ -109,7 +113,7 @@ enum {
	TMask = 16383, /* for temps hash */
	BMask = 8191, /* for blocks hash */

	K = 5041217, /* found using tools/lexh.c */
	K = 9550101, /* found using tools/lexh.c */
	M = 23,
};

@@ -1068,9 +1072,11 @@ parselnk(Lnk *lnk)
	for (haslnk=0;; haslnk=1)
		switch ((t=nextnl())) {
		case Texport:
		case Thidden:
		case Tweak:
			if (lnk->export)
				err("only one visibility allowed");
			lnk->export = 1;
			lnk->export = t - Texport + 1;
			break;
		case Tsection:
			if (lnk->sec)
@@ -1215,8 +1221,17 @@ printfn(Fn *fn, FILE *f)
	Ins *i;
	uint n;

	if (fn->lnk.export)
	switch (fn->lnk.export) {
	case 1:
		fprintf(f, "export ");
		break;
	case 2:
		fprintf(f, "hidden ");
		break;
	case 3:
		fprintf(f, "weak ");
		break;
	}
	fprintf(f, "function $%s() {\n", fn->name);
	for (b=fn->start; b; b=b->link) {
		fprintf(f, "@%s\n", b->name);
diff --git a/tools/lexh.c b/tools/lexh.c
index 8d0af21..674195e 100644
--- a/tools/lexh.c
+++ b/tools/lexh.c
@@ -25,8 +25,8 @@ char *tok[] = {
	"cgtd", "cged", "cned", "ceqd", "cod", "cuod",
	"vaarg", "vastart", "...", "env",

	"call", "phi", "jmp", "jnz", "ret", "export",
	"function", "type", "data", "section", "align",
	"call", "phi", "jmp", "jnz", "ret", "export", "hidden",
	"weak",	"function", "type", "data", "section", "align",
	"l", "w", "h", "b", "d", "s", "z", "loadw", "loadl",
	"loads", "loadd", "alloc1", "alloc2",

-- 
2.35.1