From eeeb43a60ff974ae48b21dc2fe337b1433ad58cb Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Wed, 18 Sep 2024 10:12:11 +0100 Subject: [PATCH] toobj.d unify pragmas lib/linkerdirective (#16847) * unify pragmas lib/linkerdirective --- compiler/src/dmd/toobj.d | 44 +++++++++++++++------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/compiler/src/dmd/toobj.d b/compiler/src/dmd/toobj.d index 598ad1c8c3..7e2a826020 100644 --- a/compiler/src/dmd/toobj.d +++ b/compiler/src/dmd/toobj.d @@ -785,7 +785,7 @@ void toObjFile(Dsymbol ds, bool multiobj) 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); @@ -795,19 +795,25 @@ void toObjFile(Dsymbol ds, bool multiobj) StringExp se = e.isStringExp(); char *name = cast(char *)mem.xmalloc(se.numberOfCodeUnits() + 1); + se.writeTo(name, true); - /* Embed the library names into the object file. - * The linker will then automatically - * search that library, too. - */ - if (!obj_includelib(name[0 .. strlen(name)])) + if (pd.ident == Id.linkerDirective) + obj_linkerdirective(name); + else { - /* The format does not allow embedded library names, - * so instead append the library name to the list to be passed - * to the linker. + /* Embed the library names into the object file. + * The linker will then automatically + * 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) @@ -820,24 +826,6 @@ void toObjFile(Dsymbol ds, bool multiobj) Symbol *s = toSymbol(f); 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); }