Skip to content

Commit

Permalink
Correct incorrect free in PE linker
Browse files Browse the repository at this point in the history
Summary:
The big-obj support (D3523) had introduced an early free on
the info structure. Because the pointer is not NULL'd
and the default of all the utility functions was to the
standard object format, it all kept working.

The one big-obj test that exists was subjected to a timing issue.
usually the test ran quickly enough that the allocator hasn't
had time to reclaim the memory yet, so it still passed.

This corrects it. Also as it so happens, static LLVM libraries
from mingw-w64 are compiled using big-obj.

Test Plan: ./validate

Reviewers: austin, bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13815, #13093

Differential Revision: https://phabricator.haskell.org/D3862
  • Loading branch information
Mistuke committed Aug 19, 2017
1 parent 8e5b6ec commit ee2e9ec
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rts/linker/PEi386.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
addr = (char*)cstring_from_COFF_symbol_name(
getSymShortName (info, symtab_i),
strtab);
stgFree (info);

IF_DEBUG(linker,
debugBelch("addImportSymbol `%s' => `%s'\n",
Expand Down Expand Up @@ -1471,8 +1472,6 @@ ocGetNames_PEi386 ( ObjectCode* oc )
i += getSymNumberOfAuxSymbols (info, symtab_i);
}

stgFree (info);

/* Allocate BSS space */
SymbolAddr* bss = NULL;
if (globalBssSize > 0) {
Expand Down Expand Up @@ -1570,6 +1569,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
if (result != NULL || dllInstance == 0) {
errorBelch("Could not load `%s'. Reason: %s\n",
(char*)dllName, result);
stgFree (info);
return false;
}

Expand Down Expand Up @@ -1599,8 +1599,10 @@ ocGetNames_PEi386 ( ObjectCode* oc )
sname[size-start]='\0';
stgFree(tmp);
if (!ghciInsertSymbolTable(oc->fileName, symhash, (SymbolName*)sname,
addr, false, oc))
addr, false, oc)) {
stgFree (info);
return false;
}
break;
}

Expand All @@ -1617,6 +1619,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )

if (! ghciInsertSymbolTable(oc->fileName, symhash, (SymbolName*)sname, addr,
isWeak, oc)) {
stgFree (info);
return false;
}
} else {
Expand Down Expand Up @@ -1650,6 +1653,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
i += getSymNumberOfAuxSymbols (info, symtab_i);
}

stgFree (info);
return true;
}

Expand Down

0 comments on commit ee2e9ec

Please sign in to comment.