Skip to content

Commit

Permalink
Do not emit duplicate string for pragma([lib|linkerDirective])
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator authored Sep 18, 2024
1 parent eeeb43a commit 18eeba8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions compiler/src/dmd/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -787,26 +787,46 @@ void toObjFile(Dsymbol ds, bool multiobj)
{
if (pd.ident == Id.lib || pd.ident == Id.linkerDirective)
{
__gshared int[string] pragmaLibSet;
__gshared int[string] pragmaLinkerDirectiveSet;

assert(pd.args && pd.args.length == 1);

Expression e = (*pd.args)[0];

assert(e.op == EXP.string_);

StringExp se = e.isStringExp();
char *name = cast(char *)mem.xmalloc(se.numberOfCodeUnits() + 1);
const cu = se.numberOfCodeUnits();
char *name = cast(char *)mem.xmalloc(cu + 1);
auto str = name[0 .. cu];
int[string] uniqueTab = pd.ident == Id.lib ? pragmaLibSet : pragmaLinkerDirectiveSet;
bool found = false;

se.writeTo(name, true);

if (pd.ident == Id.linkerDirective)
if (auto pkey = str in uniqueTab)
{
found = true;
mem.xfree(name);
}
else
{
uniqueTab[cast(string)str] = 1;
found = false;
}
if (found)
{
// Already emitted
}
else if (pd.ident == Id.linkerDirective)
obj_linkerdirective(name);
else
{
/* 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 (!obj_includelib(str))
{
/* The format does not allow embedded library names,
* so instead append the library name to the list to be passed
Expand Down

0 comments on commit 18eeba8

Please sign in to comment.