Implement compact file stacks in object files

Gets rid of `open_memstream`, enabling Windows compatibility again
Also fixes #491 as a nice bonus!
This commit is contained in:
ISSOtm
2020-09-29 03:40:15 +02:00
parent 930080f556
commit 5a65188ca9
23 changed files with 796 additions and 365 deletions

View File

@@ -8,9 +8,12 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include "link/object.h"
#include "link/symbol.h"
#include "link/main.h"
#include "extern/err.h"
#include "hashmap.h"
@@ -40,11 +43,15 @@ void sym_AddSymbol(struct Symbol *symbol)
/* Check if the symbol already exists */
struct Symbol *other = hash_GetElement(symbols, symbol->name);
if (other)
errx(1, "\"%s\" both in %s from %s(%" PRId32 ") and in %s from %s(%" PRId32 ")",
symbol->name,
symbol->objFileName, symbol->fileName, symbol->lineNo,
other->objFileName, other->fileName, other->lineNo);
if (other) {
fprintf(stderr, "error: \"%s\" both in %s from ", symbol->name, symbol->objFileName);
dumpFileStack(symbol->src);
fprintf(stderr, "(%" PRIu32 ") and in %s from ",
symbol->lineNo, other->objFileName);
dumpFileStack(other->src);
fprintf(stderr, "(%" PRIu32 ")\n", other->lineNo);
exit(1);
}
/* If not, add it */
bool collided = hash_AddElement(symbols, symbol->name, symbol);