Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Fix module collision detection on Linux/ld.bfd.
Browse files Browse the repository at this point in the history
This works around a linking problem with ld.bfd and --gc-sections
where __bss_start/_end become (ELF) local symbols in the main
executable. For further discussion, see:
 - http://forum.dlang.org/post/ferkvfamznsuhonokhco@forum.dlang.org
 - https://sourceware.org/bugzilla/show_bug.cgi?id=13683
 - https://issues.dlang.org/show_bug.cgi?id=879
  • Loading branch information
dnadlinger committed Jul 9, 2014
1 parent 2c941b5 commit f57df3f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/rt/sections_linux.d
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,23 @@ const(char)[] dsoName(const char* dlpi_name)
return p[0 .. strlen(p)];
}

version (LDC)
{
extern(C) extern __gshared
{
pragma(LDC_extern_weak) void* _d_execBssBegAddr;
pragma(LDC_extern_weak) void* _d_execBssEndAddr;
}
}
else
{
extern(C)
{
// .bss, .lbss, .lrodata, .ldata
extern __gshared void* __bss_start;
extern __gshared void* _end;
}
}

nothrow
void checkModuleCollisions(in ref dl_phdr_info info, in ModuleInfo*[] modules)
Expand All @@ -734,8 +745,32 @@ body
{
const(ModuleInfo)* conflicting;

version (LDC)
{
// If the main executable we have been loaded into is a D application,
// some ModuleInfos might have been copy-relocated into its .bss
// section (if it not position-independent, that is). Note that under
// normal circumstances, a ModuleInfo object is never zero-initialized,
// so by restricting our check to the BSS section, we can be sure not
// to produce false-negatives.
//
// _d_execBss{Beg, End}Addr are emitted into the entry point module
// along with main(). If the main executable is not a D program, the
// weak symbols will be undefined and we simply skip the copy-relocation
// check.
void* bss_start;
size_t bss_size;
if (&_d_execBssBegAddr && &_d_execBssEndAddr)
{
bss_start = _d_execBssBegAddr;
bss_size = _d_execBssEndAddr - bss_start;
}
}
else
{
auto bss_start = cast(void*)&__bss_start;
immutable bss_size = cast(void*)&_end - bss_start;
}

foreach (m; modules)
{
Expand Down

0 comments on commit f57df3f

Please sign in to comment.