~mpu/qbe

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH] Add visibile linkage

Details
Message ID
<ZjRLyZ5FBqinOxnc@localhost.my.domain>
DKIM signature
missing
Download raw message
Patch: +18 -3
This patch adds functionality to QBE that allows
specifying the visibility of a function, similar
to GCC's __attribute__((visible)) or MSVC's
__declspec(dllexport).

---
 all.h      |  1 +
 doc/il.txt |  5 +++++
 emit.c     |  7 +++++++
 parse.c    | 13 ++++++++++---
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/all.h b/all.h
index bb6f096..769552e 100644
--- a/all.h
+++ b/all.h
@@ -370,6 +370,7 @@ struct Addr { /* amd64 addressing */

struct Lnk {
	char export;
	char visible;
	char thread;
	char common;
	char align;
diff --git a/emit.c b/emit.c
index ba0174b..9a8e895 100644
--- a/emit.c
+++ b/emit.c
@@ -38,6 +38,13 @@ emitlnk(char *n, Lnk *l, int s, FILE *f)
			pfx, n, sfx
		);
	}
	if (l->visible) {
		fprintf(f, ".section .drectve\n");
		fprintf(f, ".ascii \" -export:\\\"%s%s\\\"", pfx, n);
		if (s == SecData)
			fprintf(f, ",data");
		fprintf(f, "\"\n");
	}
	if (l->sec) {
		fprintf(f, ".section %s", l->sec);
		if (l->secf)
diff --git a/parse.c b/parse.c
index 6dee38f..a4d8e90 100644
--- a/parse.c
+++ b/parse.c
@@ -47,6 +47,7 @@ enum Token {
	Tret,
	Thlt,
	Texport,
	Tvisible,
	Tthread,
	Tcommon,
	Tfunc,
@@ -106,6 +107,7 @@ static char *kwmap[Ntok] = {
	[Tret] = "ret",
	[Thlt] = "hlt",
	[Texport] = "export",
	[Tvisible] = "visible",
	[Tthread] = "thread",
	[Tcommon] = "common",
	[Tfunc] = "function",
@@ -273,9 +275,11 @@ lex()
		c = fgetc(inf);
		goto Alpha;
	case '#':
		while ((c=fgetc(inf)) != '\n' && c != EOF)
			;
		/* fall through */
		while ((c=fgetc(inf)) != '\n' && c != '\r' && c != EOF)
			;
		/* fall through */
	case '\r':
		return Tnl;
	case '\n':
		lnum++;
		return Tnl;
@@ -1167,6 +1171,9 @@ parselnk(Lnk *lnk)
		case Texport:
			lnk->export = 1;
			break;
		case Tvisible:
			lnk->visible = 1;
			break;
		case Tthread:
			lnk->thread = 1;
			break;
-- 
2.34.1
Details
Message ID
<e510ad77-46fc-4b76-8275-fe53e9b4c3d7@app.fastmail.com>
In-Reply-To
<ZjRLyZ5FBqinOxnc@localhost.my.domain> (view parent)
DKIM signature
pass
Download raw message
On Fri, May 3, 2024, at 04:28, Finxx wrote:
> This patch adds functionality to QBE that allows
> specifying the visibility of a function, similar
> to GCC's __attribute__((visible)) or MSVC's
> __declspec(dllexport).

I need more context here. What is the intended use
case? What does it do on the various targets?
Details
Message ID
<ec1b9343-0646-46ed-8d73-ed9aa6cd21b8@yyny.dev>
In-Reply-To
<e510ad77-46fc-4b76-8275-fe53e9b4c3d7@app.fastmail.com> (view parent)
DKIM signature
pass
Download raw message
On 5/3/24 22:13, Quentin Carbonneaux wrote:
> I need more context here. What is the intended use
> case? What does it do on the various targets?

Visibility is typically used to show/hide symbols
from dynamic libraries. Both ELF and PE support this.
I believe the default for ELF is to show all symbols,
and for PE (`.dll` files) to hide them all.
"hidden" symbols can only be accessed from other functions
inside the dynamic library, while "visible" symbols can be
accessed from any code unit linked with the dynamic library.
I believe MSVC wants a separate `.def` file containing the
"visible" symbols, and Finxx' patch gives a way
to generate those with `dlltool`.

I'm not sure what the motivation for `visible` is, but
I feel like there should be a way to hide symbols as well,
for dynamic libraries targeting ELF.

On that note:

I would like to suggest an "attribute" syntax for
codegen-unrelated/target-specific functionality.

Something like:

```
#[visibility("hidden")]
export
function $foo(
     #[vector_size(16)]
     l %a
) {
@start
     #[inline]
     call $bar(l %a)
     #[tailcall]
     ret
}
```

That way, post-processing could be done by external tools.
(I am already doing this :)

PS:
I previously used `#:attr(...)` since it is easier to parse,
and because `#` starts a comment that is ignored by QBE,
but if `#[]` becomes integrated into QBE it could be multi-line.
Details
Message ID
<c32bba39-5e4f-411c-b0b6-813299c33818@app.fastmail.com>
In-Reply-To
<ec1b9343-0646-46ed-8d73-ed9aa6cd21b8@yyny.dev> (view parent)
DKIM signature
pass
Download raw message
Thanks, the context is much clearer now. I think it is
a reasonable feature to have, and we could actually have
'export' have this behavior by default. We may then
introduce 'dsolocal' (name TBD) for symbols that need to
be visible only within the current dso.

Regardless of these considerations, the patch cannot be
merged as is as it does not work for ELF targets, so all
the targets currently explicitly supported.
Reply to thread Export thread (mbox)