summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-11-16 21:10:33 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-29 11:02:43 -0500
commit1dc0d7af974cbd88a7aa70ba61fc0d7369a20433 (patch)
tree378f26235a30ae893554baa530a21b5f923ddfeb
parentf67060c6dcc2ba14949ab5e8a4ffe46bceadc14f (diff)
downloadhaskell-1dc0d7af974cbd88a7aa70ba61fc0d7369a20433.tar.gz
linker: Introduce linker_verbose debug output
This splits the -Dl RTS debug output into two distinct flags: * `+RTS -Dl` shows errors and debug output which scales with at most O(# objects) * `+RTS -DL` shows debug output which scales with O(# symbols)t
-rw-r--r--rts/Linker.c35
-rw-r--r--rts/RtsFlags.c4
-rw-r--r--rts/include/rts/Flags.h3
-rw-r--r--rts/linker/Elf.c109
-rw-r--r--rts/linker/MachO.c88
-rw-r--r--rts/linker/PEi386.c8
6 files changed, 132 insertions, 115 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index 1b3caa0a47..57835acc91 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -727,7 +727,7 @@ addDLL( pathchar *dll_name )
MAXLINE-1);
strncpy(line, (errmsg+(match[1].rm_so)),match_length);
line[match_length] = '\0'; // make sure string is null-terminated
- IF_DEBUG(linker, debugBelch ("file name = '%s'\n", line));
+ IF_DEBUG(linker, debugBelch("file name = '%s'\n", line));
if ((fp = __rts_fopen(line, "r")) == NULL) {
return errmsg; // return original error if open fails
}
@@ -859,7 +859,7 @@ SymbolAddr* lookupDependentSymbol (SymbolName* lbl, ObjectCode *dependent)
SymbolAddr* lookupDependentSymbol (SymbolName* lbl, ObjectCode *dependent)
{
ASSERT_LOCK_HELD(&linker_mutex);
- IF_DEBUG(linker, debugBelch("lookupSymbol: looking up '%s'\n", lbl));
+ IF_DEBUG(linker_verbose, debugBelch("lookupSymbol: looking up '%s'\n", lbl));
ASSERT(symhash != NULL);
RtsSymbolInfo *pinfo;
@@ -876,7 +876,7 @@ SymbolAddr* lookupDependentSymbol (SymbolName* lbl, ObjectCode *dependent)
}
if (!ghciLookupSymbolInfo(symhash, lbl, &pinfo)) {
- IF_DEBUG(linker, debugBelch("lookupSymbol: symbol '%s' not found, trying dlsym\n", lbl));
+ IF_DEBUG(linker_verbose, debugBelch("lookupSymbol: symbol '%s' not found, trying dlsym\n", lbl));
# if defined(OBJFORMAT_ELF)
SymbolAddr *ret = internal_dlsym(lbl);
@@ -947,9 +947,10 @@ SymbolAddr* lookupDependentSymbol (SymbolName* lbl, ObjectCode *dependent)
* Symbol name only used for diagnostics output.
*/
SymbolAddr* loadSymbol(SymbolName *lbl, RtsSymbolInfo *pinfo) {
- IF_DEBUG(linker, debugBelch("lookupSymbol: value of %s is %p, owned by %" PATH_FMT "\n", lbl,
- pinfo->value,
- pinfo->owner ? OC_INFORMATIVE_FILENAME(pinfo->owner) : WSTR("No owner, probably built-in.")));
+ IF_DEBUG(linker_verbose,
+ debugBelch("lookupSymbol: value of %s is %p, owned by %" PATH_FMT "\n", lbl,
+ pinfo->value,
+ pinfo->owner ? OC_INFORMATIVE_FILENAME(pinfo->owner) : WSTR("No owner, probably built-in.")));
ObjectCode* oc = pinfo->owner;
/* Symbol can be found during linking, but hasn't been relocated. Do so now.
@@ -1111,7 +1112,7 @@ mmapForLinker (size_t bytes, uint32_t prot, uint32_t flags, int fd, int offset)
: TRY_MAP_32BIT;
static uint32_t fixed = 0;
- IF_DEBUG(linker, debugBelch("mmapForLinker: start\n"));
+ IF_DEBUG(linker_verbose, debugBelch("mmapForLinker: start\n"));
size = roundUpToPage(bytes);
#if defined(MAP_LOW_MEM)
@@ -1122,9 +1123,9 @@ mmap_again:
map_addr = mmap_32bit_base;
}
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("mmapForLinker: \tprotection %#0x\n", prot));
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("mmapForLinker: \tflags %#0x\n",
MAP_PRIVATE | tryMap32Bit | fixed | flags));
@@ -1206,10 +1207,10 @@ mmap_again:
// }
#endif
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("mmapForLinker: mapped %" FMT_Word
" bytes starting at %p\n", (W_)size, result));
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("mmapForLinker: done\n"));
return result;
@@ -1263,7 +1264,7 @@ void mmapForLinkerMarkExecutable(void *start, size_t len)
if (len == 0) {
return;
}
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("mmapForLinkerMarkExecutable: protecting %" FMT_Word
" bytes starting at %p\n", (W_)len, start));
if (mprotect(start, len, PROT_READ|PROT_EXEC) == -1) {
@@ -1341,6 +1342,8 @@ freePreloadObjectFile (ObjectCode *oc)
*/
void freeObjectCode (ObjectCode *oc)
{
+ IF_DEBUG(linker, debugBelch("freeObjectCode: %s", oc->fileName));
+
if (oc->type == DYNAMIC_OBJECT) {
#if defined(OBJFORMAT_ELF)
ACQUIRE_LOCK(&dl_mutex);
@@ -1439,7 +1442,8 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
bool mapped, pathchar *archiveMemberName, int misalignment ) {
ObjectCode* oc;
- IF_DEBUG(linker, debugBelch("mkOc: start\n"));
+
+ IF_DEBUG(linker, debugBelch("mkOc: %s\n", path));
oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)");
oc->info = NULL;
@@ -1507,7 +1511,6 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
oc->nc_ranges = NULL;
oc->dlopen_handle = NULL;
- IF_DEBUG(linker, debugBelch("mkOc: done\n"));
return oc;
}
@@ -1694,7 +1697,7 @@ HsInt loadOc (ObjectCode* oc)
{
int r;
- IF_DEBUG(linker, debugBelch("loadOc: start\n"));
+ IF_DEBUG(linker, debugBelch("loadOc: start (%s)\n", oc->fileName));
/* verify the in-memory image */
# if defined(OBJFORMAT_ELF)
@@ -1778,7 +1781,7 @@ HsInt loadOc (ObjectCode* oc)
oc->status = OBJECT_LOADED;
}
}
- IF_DEBUG(linker, debugBelch("loadOc: done.\n"));
+ IF_DEBUG(linker, debugBelch("loadOc: done (%s).\n", oc->fileName));
return 1;
}
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index 0d41108822..426f04a70c 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -199,6 +199,7 @@ void initRtsFlagsDefaults(void)
RtsFlags.DebugFlags.prof = false;
RtsFlags.DebugFlags.apply = false;
RtsFlags.DebugFlags.linker = false;
+ RtsFlags.DebugFlags.linker_verbose = false;
RtsFlags.DebugFlags.squeeze = false;
RtsFlags.DebugFlags.hpc = false;
RtsFlags.DebugFlags.sparks = false;
@@ -2142,6 +2143,9 @@ static void read_debug_flags(const char* arg)
case 'l':
RtsFlags.DebugFlags.linker = true;
break;
+ case 'L':
+ RtsFlags.DebugFlags.linker_verbose = true;
+ break;
case 'a':
RtsFlags.DebugFlags.apply = true;
break;
diff --git a/rts/include/rts/Flags.h b/rts/include/rts/Flags.h
index 9291f492cf..2936876b7a 100644
--- a/rts/include/rts/Flags.h
+++ b/rts/include/rts/Flags.h
@@ -104,7 +104,8 @@ typedef struct _DEBUG_FLAGS {
bool zero_on_gc; /* 'Z' */
bool stable; /* 't' */
bool prof; /* 'p' */
- bool linker; /* 'l' the object linker */
+ bool linker; /* 'l' the object linker, output which scales with O(# objects) or errors */
+ bool linker_verbose; /* 'L' the object linker, output which scales with O(# symbols) */
bool apply; /* 'a' */
bool stm; /* 'm' */
bool squeeze; /* 'z' stack squeezing & lazy blackholing */
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index f6a1754257..06afae631d 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -378,7 +378,7 @@ ocVerifyImage_ELF ( ObjectCode* oc )
errorBelch("%s: not a relocatable object (.o) file", oc->fileName);
return 0;
}
- IF_DEBUG(linker, debugBelch( "Is a relocatable object (.o) file\n" ));
+ IF_DEBUG(linker,debugBelch( "Is a relocatable object (.o) file\n" ));
IF_DEBUG(linker,debugBelch( "Architecture is " ));
switch (ehdr->e_machine) {
@@ -446,11 +446,11 @@ ocVerifyImage_ELF ( ObjectCode* oc )
}
for (i = 0; i < shnum; i++) {
- IF_DEBUG(linker,debugBelch("%2d: ", i ));
- IF_DEBUG(linker,debugBelch("type=%2d ", (int)shdr[i].sh_type ));
- IF_DEBUG(linker,debugBelch("size=%4d ", (int)shdr[i].sh_size ));
- IF_DEBUG(linker,debugBelch("offs=%4d ", (int)shdr[i].sh_offset ));
- IF_DEBUG(linker,debugBelch(" (%p .. %p) ",
+ IF_DEBUG(linker_verbose,debugBelch("%2d: ", i ));
+ IF_DEBUG(linker_verbose,debugBelch("type=%2d ", (int)shdr[i].sh_type ));
+ IF_DEBUG(linker_verbose,debugBelch("size=%4d ", (int)shdr[i].sh_size ));
+ IF_DEBUG(linker_verbose,debugBelch("offs=%4d ", (int)shdr[i].sh_offset ));
+ IF_DEBUG(linker_verbose,debugBelch(" (%p .. %p) ",
ehdrC + shdr[i].sh_offset,
ehdrC + shdr[i].sh_offset + shdr[i].sh_size - 1));
@@ -460,7 +460,7 @@ ocVerifyImage_ELF ( ObjectCode* oc )
case SHT_REL:
case SHT_RELA:
- IF_DEBUG(linker,debugBelch( shdr[i].sh_type == SHT_REL ? "Rel " : "RelA "));
+ IF_DEBUG(linker_verbose,debugBelch( shdr[i].sh_type == SHT_REL ? "Rel " : "RelA "));
if (!SECTION_INDEX_VALID(shdr[i].sh_link)) {
if (shdr[i].sh_link == SHN_UNDEF)
@@ -488,7 +488,7 @@ ocVerifyImage_ELF ( ObjectCode* oc )
break;
case SHT_SYMTAB:
- IF_DEBUG(linker,debugBelch("Sym "));
+ IF_DEBUG(linker_verbose,debugBelch("Sym "));
if (!SECTION_INDEX_VALID(shdr[i].sh_link)) {
errorBelch("\n%s: symbol table section #%d has an invalid link field (%d)\n",
@@ -503,15 +503,15 @@ ocVerifyImage_ELF ( ObjectCode* oc )
return 0;
}
break;
- case SHT_STRTAB: IF_DEBUG(linker,debugBelch("Str ")); break;
- default: IF_DEBUG(linker,debugBelch(" ")); break;
+ case SHT_STRTAB: IF_DEBUG(linker_verbose,debugBelch("Str ")); break;
+ default: IF_DEBUG(linker_verbose,debugBelch(" ")); break;
}
if (sh_strtab) {
- IF_DEBUG(linker,debugBelch("sname=%s\n", sh_strtab + shdr[i].sh_name ));
+ IF_DEBUG(linker_verbose,debugBelch("sname=%s\n", sh_strtab + shdr[i].sh_name ));
}
}
- IF_DEBUG(linker,debugBelch( "\nString tables\n" ));
+ IF_DEBUG(linker_verbose,debugBelch( "\nString tables\n" ));
nstrtab = 0;
for (i = 0; i < shnum; i++) {
if (shdr[i].sh_type == SHT_STRTAB
@@ -521,25 +521,25 @@ ocVerifyImage_ELF ( ObjectCode* oc )
debugging info. */
&& 0 != memcmp(".stabstr", sh_strtab + shdr[i].sh_name, 8)
) {
- IF_DEBUG(linker,debugBelch(" section %d is a normal string table\n", i ));
+ IF_DEBUG(linker_verbose,debugBelch(" section %d is a normal string table\n", i ));
nstrtab++;
}
}
if (nstrtab == 0) {
- IF_DEBUG(linker,debugBelch(" no normal string tables (potentially, but not necessarily a problem)\n"));
+ IF_DEBUG(linker_verbose,debugBelch(" no normal string tables (potentially, but not necessarily a problem)\n"));
}
#if defined(SHN_XINDEX)
Elf_Word* shndxTable = get_shndx_table(ehdr);
#endif
nsymtabs = 0;
- IF_DEBUG(linker,debugBelch( "Symbol tables\n" ));
+ IF_DEBUG(linker_verbose,debugBelch( "Symbol tables\n" ));
for (i = 0; i < shnum; i++) {
if (shdr[i].sh_type != SHT_SYMTAB) continue;
- IF_DEBUG(linker,debugBelch( "section %d is a symbol table\n", i ));
+ IF_DEBUG(linker_verbose,debugBelch( "section %d is a symbol table\n", i ));
nsymtabs++;
stab = (Elf_Sym*) (ehdrC + shdr[i].sh_offset);
nent = shdr[i].sh_size / sizeof(Elf_Sym);
- IF_DEBUG(linker,debugBelch( " number of entries is apparently %d (%ld rem)\n",
+ IF_DEBUG(linker_verbose,debugBelch( " number of entries is apparently %d (%ld rem)\n",
nent,
(long)shdr[i].sh_size % sizeof(Elf_Sym)
));
@@ -556,34 +556,34 @@ ocVerifyImage_ELF ( ObjectCode* oc )
secno = shndxTable[j];
}
#endif
- IF_DEBUG(linker,debugBelch(" %2d ", j ));
- IF_DEBUG(linker,debugBelch(" sec=%-5d size=%-3d val=%5p ",
+ IF_DEBUG(linker_verbose,debugBelch(" %2d ", j ));
+ IF_DEBUG(linker_verbose,debugBelch(" sec=%-5d size=%-3d val=%5p ",
(int)secno,
(int)stab[j].st_size,
(char*)stab[j].st_value ));
- IF_DEBUG(linker,debugBelch("type=" ));
+ IF_DEBUG(linker_verbose,debugBelch("type=" ));
switch (ELF_ST_TYPE(stab[j].st_info)) {
- case STT_NOTYPE: IF_DEBUG(linker,debugBelch("notype " )); break;
- case STT_OBJECT: IF_DEBUG(linker,debugBelch("object " )); break;
- case STT_FUNC : IF_DEBUG(linker,debugBelch("func " )); break;
- case STT_SECTION: IF_DEBUG(linker,debugBelch("section" )); break;
- case STT_FILE: IF_DEBUG(linker,debugBelch("file " )); break;
- default: IF_DEBUG(linker,debugBelch("? " )); break;
+ case STT_NOTYPE: IF_DEBUG(linker_verbose,debugBelch("notype " )); break;
+ case STT_OBJECT: IF_DEBUG(linker_verbose,debugBelch("object " )); break;
+ case STT_FUNC : IF_DEBUG(linker_verbose,debugBelch("func " )); break;
+ case STT_SECTION: IF_DEBUG(linker_verbose,debugBelch("section" )); break;
+ case STT_FILE: IF_DEBUG(linker_verbose,debugBelch("file " )); break;
+ default: IF_DEBUG(linker_verbose,debugBelch("? " )); break;
}
- IF_DEBUG(linker,debugBelch(" " ));
+ IF_DEBUG(linker_verbose,debugBelch(" " ));
- IF_DEBUG(linker,debugBelch("bind=" ));
+ IF_DEBUG(linker_verbose,debugBelch("bind=" ));
switch (ELF_ST_BIND(stab[j].st_info)) {
- case STB_LOCAL : IF_DEBUG(linker,debugBelch("local " )); break;
- case STB_GLOBAL: IF_DEBUG(linker,debugBelch("global" )); break;
- case STB_WEAK : IF_DEBUG(linker,debugBelch("weak " )); break;
- default: IF_DEBUG(linker,debugBelch("? " )); break;
+ case STB_LOCAL : IF_DEBUG(linker_verbose,debugBelch("local " )); break;
+ case STB_GLOBAL: IF_DEBUG(linker_verbose,debugBelch("global" )); break;
+ case STB_WEAK : IF_DEBUG(linker_verbose,debugBelch("weak " )); break;
+ default: IF_DEBUG(linker_verbose,debugBelch("? " )); break;
}
- IF_DEBUG(linker,debugBelch(" " ));
+ IF_DEBUG(linker_verbose,debugBelch(" " ));
- IF_DEBUG(linker,debugBelch("other=%2x ", stab[j].st_other ));
- IF_DEBUG(linker,debugBelch("name=%s [%x]\n",
+ IF_DEBUG(linker_verbose,debugBelch("other=%2x ", stab[j].st_other ));
+ IF_DEBUG(linker_verbose,debugBelch("name=%s [%x]\n",
ehdrC + shdr[shdr[i].sh_link].sh_offset
+ stab[j].st_name, stab[j].st_name ));
}
@@ -593,7 +593,7 @@ ocVerifyImage_ELF ( ObjectCode* oc )
// Not having a symbol table is not in principle a problem.
// When an object file has no symbols then the 'strip' program
// typically will remove the symbol table entirely.
- IF_DEBUG(linker,debugBelch(" no symbol tables (potentially, but not necessarily a problem)\n"));
+ IF_DEBUG(linker_verbose,debugBelch(" no symbol tables (potentially, but not necessarily a problem)\n"));
}
return 1;
@@ -928,7 +928,7 @@ ocGetNames_ELF ( ObjectCode* oc )
common_used += symbol->elf_sym->st_size;
CHECK(common_used <= common_size);
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("COMMON symbol, size %llu name %s allocated at %p\n",
(long long unsigned int) symbol->elf_sym->st_size, nm, symbol->addr));
@@ -970,7 +970,7 @@ ocGetNames_ELF ( ObjectCode* oc )
isLocal = true;
isWeak = false;
} else { /* STB_GLOBAL or STB_WEAK */
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("addOTabName(GLOB): %10p %s %s\n",
symbol->addr, oc->fileName, nm));
isLocal = false;
@@ -1000,7 +1000,7 @@ ocGetNames_ELF ( ObjectCode* oc )
}
} else {
/* Skip. */
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("skipping `%s'\n",
nm)
);
@@ -1068,13 +1068,13 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
CHECK(stab != NULL);
targ = (Elf_Word*)oc->sections[target_shndx].start;
- IF_DEBUG(linker,debugBelch(
+ IF_DEBUG(linker_verbose,debugBelch(
"relocations for section %d using symtab %d\n",
target_shndx, symtab_shndx));
/* Skip sections that we're not interested in. */
if (oc->sections[target_shndx].kind == SECTIONKIND_OTHER) {
- IF_DEBUG(linker,debugBelch( "skipping (target section not loaded)"));
+ IF_DEBUG(linker_verbose,debugBelch( "skipping (target section not loaded)"));
return 1;
}
@@ -1114,10 +1114,10 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
ElfSymbol * symbol = NULL;
- IF_DEBUG(linker,debugBelch( "Rel entry %3d is raw(%6p %6p): ",
+ IF_DEBUG(linker_verbose,debugBelch( "Rel entry %3d is raw(%6p %6p): ",
j, (void*)offset, (void*)info ));
if (!info) {
- IF_DEBUG(linker,debugBelch( " ZERO" ));
+ IF_DEBUG(linker_verbose,debugBelch( " ZERO" ));
S = 0;
} else {
symbol = &stab->symbols[ELF_R_SYM(info)];
@@ -1133,7 +1133,7 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
oc->fileName, symbol->name);
return 0;
}
- IF_DEBUG(linker,debugBelch( "`%s' resolves to %p\n", symbol->name,
+ IF_DEBUG(linker_verbose,debugBelch( "`%s' resolves to %p\n", symbol->name,
(void*)S ));
#if defined(arm_HOST_ARCH)
@@ -1172,8 +1172,9 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
}
int reloc_type = ELF_R_TYPE(info);
- IF_DEBUG(linker,debugBelch("Reloc: P = %p S = %p A = %p type=%d\n",
- (void*)P, (void*)S, (void*)A, reloc_type ));
+ IF_DEBUG(linker_verbose,
+ debugBelch("Reloc: P = %p S = %p A = %p type=%d\n",
+ (void*)P, (void*)S, (void*)A, reloc_type ));
checkProddableBlock ( oc, pP, sizeof(Elf_Word) );
#if defined(i386_HOST_ARCH)
@@ -1286,7 +1287,7 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
const StgWord32 hBit = (result & 0x2) >> 1;
// Change instruction to BLX
*word = (*word & ~0xFF000000) | ((0xfa | hBit) << 24);
- IF_DEBUG(linker, debugBelch("Changed BL to BLX at %p\n", word));
+ IF_DEBUG(linker_verbose, debugBelch("Changed BL to BLX at %p\n", word));
}
break;
}
@@ -1489,12 +1490,12 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
stab = (Elf_Sym*) (ehdrC + shdr[ symtab_shndx ].sh_offset);
strtab= (char*) (ehdrC + shdr[ strtab_shndx ].sh_offset);
- IF_DEBUG(linker,debugBelch( "relocations for section %d using symtab %d\n",
+ IF_DEBUG(linker_verbose,debugBelch( "relocations for section %d using symtab %d\n",
target_shndx, symtab_shndx ));
/* Skip sections that we're not interested in. */
if (oc->sections[target_shndx].kind == SECTIONKIND_OTHER) {
- IF_DEBUG(linker,debugBelch( "skipping (target section not loaded)"));
+ IF_DEBUG(linker_verbose,debugBelch( "skipping (target section not loaded)"));
return 1;
}
@@ -1520,11 +1521,11 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
Elf_Sword delta;
# endif
- IF_DEBUG(linker,debugBelch( "Rel entry %3d is raw(%6p %6p %6p) ",
+ IF_DEBUG(linker_verbose,debugBelch( "Rel entry %3d is raw(%6p %6p %6p) ",
j, (void*)offset, (void*)info,
(void*)A ));
if (!info) {
- IF_DEBUG(linker,debugBelch( " ZERO" ));
+ IF_DEBUG(linker_verbose,debugBelch( " ZERO" ));
S = 0;
} else {
Elf_Sym sym = stab[ELF_R_SYM(info)];
@@ -1583,13 +1584,13 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
errorBelch("%s: unknown symbol `%s'", oc->fileName, symbol);
return 0;
}
- IF_DEBUG(linker,debugBelch("`%s' resolves to %p\n", symbol, (void*)S));
+ IF_DEBUG(linker_verbose,debugBelch("`%s' resolves to %p\n", symbol, (void*)S));
}
#if defined(DEBUG) || defined(sparc_HOST_ARCH) || defined(powerpc_HOST_ARCH) \
|| defined(x86_64_HOST_ARCH)
- IF_DEBUG(linker,debugBelch("Reloc: P = %p S = %p A = %p\n",
- (void*)P, (void*)S, (void*)A ));
+ IF_DEBUG(linker_verbose,debugBelch("Reloc: P = %p S = %p A = %p\n",
+ (void*)P, (void*)S, (void*)A ));
checkProddableBlock(oc, (void*)P, sizeof(Elf_Word));
#endif
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index 1a18ee6a74..02f2a30605 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -663,14 +663,14 @@ relocateSection(ObjectCode* oc, int curSection)
int relocLenBytes;
int nextInstrAdj = 0;
- IF_DEBUG(linker, debugBelch("relocateSection: relocation %d\n", i));
- IF_DEBUG(linker, debugBelch(" : type = %d\n", reloc->r_type));
- IF_DEBUG(linker, debugBelch(" : address = %d\n", reloc->r_address));
- IF_DEBUG(linker, debugBelch(" : symbolnum = %u\n", reloc->r_symbolnum));
- IF_DEBUG(linker, debugBelch(" : pcrel = %d\n", reloc->r_pcrel));
- IF_DEBUG(linker, debugBelch(" : length = %d\n", reloc->r_length));
- IF_DEBUG(linker, debugBelch(" : extern = %d\n", reloc->r_extern));
- IF_DEBUG(linker, debugBelch(" : type = %d\n", reloc->r_type));
+ IF_DEBUG(linker_verbose, debugBelch("relocateSection: relocation %d\n", i));
+ IF_DEBUG(linker_verbose, debugBelch(" : type = %d\n", reloc->r_type));
+ IF_DEBUG(linker_verbose, debugBelch(" : address = %d\n", reloc->r_address));
+ IF_DEBUG(linker_verbose, debugBelch(" : symbolnum = %u\n", reloc->r_symbolnum));
+ IF_DEBUG(linker_verbose, debugBelch(" : pcrel = %d\n", reloc->r_pcrel));
+ IF_DEBUG(linker_verbose, debugBelch(" : length = %d\n", reloc->r_length));
+ IF_DEBUG(linker_verbose, debugBelch(" : extern = %d\n", reloc->r_extern));
+ IF_DEBUG(linker_verbose, debugBelch(" : type = %d\n", reloc->r_type));
switch(reloc->r_length)
{
@@ -714,7 +714,7 @@ relocateSection(ObjectCode* oc, int curSection)
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("relocateSection: length = %d, thing = %" PRId64 ", baseValue = %p\n",
reloc->r_length, thing, (char *)baseValue));
@@ -725,7 +725,7 @@ relocateSection(ObjectCode* oc, int curSection)
SymbolName* nm = symbol->name;
SymbolAddr* addr = NULL;
- IF_DEBUG(linker, debugBelch("relocateSection: making jump island for %s, extern = %d, X86_64_RELOC_GOT\n",
+ IF_DEBUG(linker_verbose, debugBelch("relocateSection: making jump island for %s, extern = %d, X86_64_RELOC_GOT\n",
nm, reloc->r_extern));
if (reloc->r_extern == 0) {
@@ -739,9 +739,10 @@ relocateSection(ObjectCode* oc, int curSection)
// to resolve it.
addr = lookupDependentSymbol(nm, oc);
- IF_DEBUG(linker, debugBelch("relocateSection: looked up %s, "
- "external X86_64_RELOC_GOT or X86_64_RELOC_GOT_LOAD\n"
- " : addr = %p\n", nm, addr));
+ IF_DEBUG(linker_verbose,
+ debugBelch("relocateSection: looked up %s, "
+ "external X86_64_RELOC_GOT or X86_64_RELOC_GOT_LOAD\n"
+ " : addr = %p\n", nm, addr));
if (addr == NULL) {
errorBelch("\nlookupSymbol failed in relocateSection (RELOC_GOT)\n"
@@ -749,7 +750,7 @@ relocateSection(ObjectCode* oc, int curSection)
return 0;
}
} else {
- IF_DEBUG(linker, debugBelch("relocateSection: %s is not an exported symbol\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch("relocateSection: %s is not an exported symbol\n", nm));
// The symbol is not exported, or defined in another
// module, so it must be in the current object module,
@@ -764,9 +765,11 @@ relocateSection(ObjectCode* oc, int curSection)
addr = symbol->addr;
- IF_DEBUG(linker, debugBelch("relocateSection: calculated relocation of "
- "non-external X86_64_RELOC_GOT or X86_64_RELOC_GOT_LOAD\n"));
- IF_DEBUG(linker, debugBelch(" : addr = %p\n", addr));
+ IF_DEBUG(linker_verbose,
+ debugBelch("relocateSection: calculated relocation of "
+ "non-external X86_64_RELOC_GOT or X86_64_RELOC_GOT_LOAD\n"));
+ IF_DEBUG(linker_verbose,
+ debugBelch(" : addr = %p\n", addr));
} else {
errorBelch("\nrelocateSection: %s is not exported,"
" and should be defined in a section, but isn't!\n", nm);
@@ -786,17 +789,18 @@ relocateSection(ObjectCode* oc, int curSection)
SymbolName* nm = symbol->name;
SymbolAddr* addr = NULL;
- IF_DEBUG(linker, debugBelch("relocateSection: looking up external symbol %s\n", nm));
- IF_DEBUG(linker, debugBelch(" : type = %d\n", symbol->nlist->n_type));
- IF_DEBUG(linker, debugBelch(" : sect = %d\n", symbol->nlist->n_sect));
- IF_DEBUG(linker, debugBelch(" : desc = %d\n", symbol->nlist->n_desc));
- IF_DEBUG(linker, debugBelch(" : value = %p\n", (void *)symbol->nlist->n_value));
+ IF_DEBUG(linker_verbose, debugBelch("relocateSection: looking up external symbol %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch(" : type = %d\n", symbol->nlist->n_type));
+ IF_DEBUG(linker_verbose, debugBelch(" : sect = %d\n", symbol->nlist->n_sect));
+ IF_DEBUG(linker_verbose, debugBelch(" : desc = %d\n", symbol->nlist->n_desc));
+ IF_DEBUG(linker_verbose, debugBelch(" : value = %p\n", (void *)symbol->nlist->n_value));
if ((symbol->nlist->n_type & N_TYPE) == N_SECT) {
CHECK(symbol->addr != NULL);
value = (uint64_t) symbol->addr;
- IF_DEBUG(linker, debugBelch("relocateSection, defined external symbol %s, relocated address %p\n",
- nm, (void *)value));
+ IF_DEBUG(linker_verbose,
+ debugBelch("relocateSection, defined external symbol %s, relocated address %p\n",
+ nm, (void *)value));
}
else {
addr = lookupDependentSymbol(nm, oc);
@@ -808,7 +812,9 @@ relocateSection(ObjectCode* oc, int curSection)
}
value = (uint64_t) addr;
- IF_DEBUG(linker, debugBelch("relocateSection: external symbol %s, address %p\n", nm, (void *)value));
+ IF_DEBUG(linker_verbose,
+ debugBelch("relocateSection: external symbol %s, address %p\n",
+ nm, (void *)value));
}
}
else
@@ -832,7 +838,7 @@ relocateSection(ObjectCode* oc, int curSection)
Section * targetSec = &oc->sections[targetSecNum];
MachOSection * targetMacho = targetSec->info->macho_section;
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("relocateSection: internal relocation relative to section %d (%s, %s)\n",
targetSecNum, targetMacho->segname, targetMacho->sectname));
@@ -843,13 +849,15 @@ relocateSection(ObjectCode* oc, int curSection)
thing, (uint64_t) targetMacho->addr);
uint64_t thingRelativeOffset = thing - targetMacho->addr;
- IF_DEBUG(linker, debugBelch(" "
- "unsigned displacement %" PRIx64 " with section relative offset %" PRIx64 "\n",
+ IF_DEBUG(linker_verbose,
+ debugBelch(" "
+ "unsigned displacement %" PRIx64 " with section relative offset %" PRIx64 "\n",
thing, thingRelativeOffset));
thing = (uint64_t) targetSec->start + thingRelativeOffset;
- IF_DEBUG(linker, debugBelch(" "
- "relocated address is %p\n", (void *) thing));
+ IF_DEBUG(linker_verbose,
+ debugBelch(" "
+ "relocated address is %p\n", (void *) thing));
/* Compared to external relocation we don't need to adjust value
* any further since thing already has absolute address.
@@ -869,7 +877,7 @@ relocateSection(ObjectCode* oc, int curSection)
(void *) imThingLoc, (void *) targetMacho->addr);
int64_t thingRelativeOffset = imThingLoc - targetMacho->addr;
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch(" "
"original displacement %" PRId64 " to %p with section relative offset %" PRIu64 "\n",
thing, (void *) imThingLoc, thingRelativeOffset));
@@ -877,7 +885,7 @@ relocateSection(ObjectCode* oc, int curSection)
thing = (int64_t) ((uint64_t) targetSec->start + thingRelativeOffset)
- ((uint64_t) sect->start + baseValueOffset);
value = baseValue; // so that it further cancels out with baseValue
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch(" "
"relocated displacement %" PRId64 " to %p\n",
(int64_t) thing, (void *) (baseValue + thing)));
@@ -889,7 +897,7 @@ relocateSection(ObjectCode* oc, int curSection)
}
}
- IF_DEBUG(linker, debugBelch("relocateSection: value = %p\n", (void *) value));
+ IF_DEBUG(linker_verbose, debugBelch("relocateSection: value = %p\n", (void *) value));
if (type == X86_64_RELOC_BRANCH)
{
@@ -924,7 +932,7 @@ relocateSection(ObjectCode* oc, int curSection)
barf("unknown relocation");
}
- IF_DEBUG(linker, debugBelch("relocateSection: thing = %p\n", (void *) thing));
+ IF_DEBUG(linker_verbose, debugBelch("relocateSection: thing = %p\n", (void *) thing));
/* Thing points to memory within one of the relocated sections. We can
* probe the first byte to sanity check internal relocations.
@@ -1326,7 +1334,7 @@ ocGetNames_MachO(ObjectCode* oc)
SymbolName* nm = oc->info->macho_symbols[i].name;
if (oc->info->nlist[i].n_type & N_STAB)
{
- IF_DEBUG(linker, debugBelch("ocGetNames_MachO: Skip STAB: %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch("ocGetNames_MachO: Skip STAB: %s\n", nm));
}
else if ((oc->info->nlist[i].n_type & N_TYPE) == N_SECT)
{
@@ -1335,11 +1343,11 @@ ocGetNames_MachO(ObjectCode* oc)
if ( (oc->info->nlist[i].n_desc & N_WEAK_DEF)
&& lookupDependentSymbol(nm, oc)) {
// weak definition, and we already have a definition
- IF_DEBUG(linker, debugBelch(" weak: %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch(" weak: %s\n", nm));
}
else
{
- IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch("ocGetNames_MachO: inserting %s\n", nm));
SymbolAddr* addr = oc->info->macho_symbols[i].addr;
ghciInsertSymbolTable( oc->fileName
@@ -1356,12 +1364,12 @@ ocGetNames_MachO(ObjectCode* oc)
}
else
{
- IF_DEBUG(linker, debugBelch("ocGetNames_MachO: \t...not external, skipping %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch("ocGetNames_MachO: \t...not external, skipping %s\n", nm));
}
}
else
{
- IF_DEBUG(linker, debugBelch("ocGetNames_MachO: \t...not defined in this section, skipping %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch("ocGetNames_MachO: \t...not defined in this section, skipping %s\n", nm));
}
}
}
@@ -1384,7 +1392,7 @@ ocGetNames_MachO(ObjectCode* oc)
/* also set the final address to the macho_symbol */
oc->info->macho_symbols[i].addr = (void*)commonCounter;
- IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting common symbol: %s\n", nm));
+ IF_DEBUG(linker_verbose, debugBelch("ocGetNames_MachO: inserting common symbol: %s\n", nm));
ghciInsertSymbolTable(oc->fileName, symhash, nm,
(void*)commonCounter, HS_BOOL_FALSE, oc);
oc->symbols[curSymbol].name = nm;
diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c
index f39930c8c5..9f955e1cf8 100644
--- a/rts/linker/PEi386.c
+++ b/rts/linker/PEi386.c
@@ -1689,7 +1689,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
Allocate zeroed space for it from the BSS section */
addr = bss;
bss = (SymbolAddr*)((StgWord)bss + (StgWord)symValue);
- IF_DEBUG(linker, debugBelch("bss symbol @ %p %u\n", addr, symValue));
+ IF_DEBUG(linker_verbose, debugBelch("bss symbol @ %p %u\n", addr, symValue));
}
else if (secNumber > 0
&& section
@@ -1708,7 +1708,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
sym = &oc->info->symbols[oc->n_symbols-1];
sname = get_sym_name (getSymShortName (info, sym), oc);
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch("loading symbol `%s' from dll: '%ls' => `%s'\n",
sname, oc->fileName, dllName));
@@ -1761,7 +1761,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
&& (!section || (section && section->kind != SECTIONKIND_IMPORT))) {
/* debugBelch("addSymbol %p `%s' Weak:%lld \n", addr, sname, isWeak); */
sname = strdup (sname);
- IF_DEBUG(linker, debugBelch("addSymbol %p `%s'\n", addr, sname));
+ IF_DEBUG(linker_verbose, debugBelch("addSymbol %p `%s'\n", addr, sname));
ASSERT(i < (uint32_t)oc->n_symbols);
oc->symbols[i].name = sname;
oc->symbols[i].addr = addr;
@@ -1869,7 +1869,7 @@ ocResolve_PEi386 ( ObjectCode* oc )
uint64_t symIndex = reloc->SymbolTableIndex;
sym = &oc->info->symbols[symIndex];
- IF_DEBUG(linker,
+ IF_DEBUG(linker_verbose,
debugBelch(
"reloc sec %2d num %3d: type 0x%-4x "
"vaddr 0x%-8lx name `",