toobj.d unify pragmas lib/linkerdirective (#16847)

* unify pragmas lib/linkerdirective
This commit is contained in:
Nicholas Wilson 2024-09-18 10:12:11 +01:00 committed by GitHub
parent 0e8e67097d
commit eeeb43a60f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -785,7 +785,7 @@ void toObjFile(Dsymbol ds, bool multiobj)
override void visit(PragmaDeclaration pd) override void visit(PragmaDeclaration pd)
{ {
if (pd.ident == Id.lib) if (pd.ident == Id.lib || pd.ident == Id.linkerDirective)
{ {
assert(pd.args && pd.args.length == 1); assert(pd.args && pd.args.length == 1);
@ -795,19 +795,25 @@ void toObjFile(Dsymbol ds, bool multiobj)
StringExp se = e.isStringExp(); StringExp se = e.isStringExp();
char *name = cast(char *)mem.xmalloc(se.numberOfCodeUnits() + 1); char *name = cast(char *)mem.xmalloc(se.numberOfCodeUnits() + 1);
se.writeTo(name, true); se.writeTo(name, true);
/* Embed the library names into the object file. if (pd.ident == Id.linkerDirective)
* The linker will then automatically obj_linkerdirective(name);
* search that library, too. else
*/
if (!obj_includelib(name[0 .. strlen(name)]))
{ {
/* The format does not allow embedded library names, /* Embed the library names into the object file.
* so instead append the library name to the list to be passed * The linker will then automatically
* to the linker. * search that library, too.
*/ */
global.params.libfiles.push(name); if (!obj_includelib(name[0 .. strlen(name)]))
{
/* The format does not allow embedded library names,
* so instead append the library name to the list to be passed
* to the linker.
*/
global.params.libfiles.push(name);
}
} }
} }
else if (pd.ident == Id.startaddress) else if (pd.ident == Id.startaddress)
@ -820,24 +826,6 @@ void toObjFile(Dsymbol ds, bool multiobj)
Symbol *s = toSymbol(f); Symbol *s = toSymbol(f);
obj_startaddress(s); obj_startaddress(s);
} }
else if (pd.ident == Id.linkerDirective)
{
assert(pd.args && pd.args.length == 1);
Expression e = (*pd.args)[0];
assert(e.op == EXP.string_);
StringExp se = e.isStringExp();
size_t length = se.numberOfCodeUnits() + 1;
debug enum LEN = 2; else enum LEN = 20;
char[LEN] buffer = void;
SmallBuffer!char directive = SmallBuffer!char(length, buffer);
se.writeTo(directive.ptr, true);
obj_linkerdirective(directive.ptr);
}
visit(cast(AttribDeclaration)pd); visit(cast(AttribDeclaration)pd);
} }