Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1379 from MartinNowak/sections
Browse files Browse the repository at this point in the history
use linker generated section brackets
  • Loading branch information
WalterBright committed Sep 6, 2015
2 parents b83f84e + e91f59d commit 0df48a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 74 deletions.
47 changes: 10 additions & 37 deletions src/rt/sections_android.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct SectionGroup

@property immutable(FuncTable)[] ehTables() const
{
auto pbeg = cast(immutable(FuncTable)*)&_deh_beg;
auto pend = cast(immutable(FuncTable)*)&_deh_end;
auto pbeg = cast(immutable(FuncTable)*)&__start_deh;
auto pend = cast(immutable(FuncTable)*)&__stop_deh;
return pbeg[0 .. pend - pbeg];
}

Expand All @@ -62,7 +62,10 @@ private:
void initSections()
{
pthread_key_create(&_tlsKey, null);
_sections.moduleGroup = ModuleGroup(getModuleInfos());

auto mbeg = cast(immutable ModuleInfo**)&__start_minfo;
auto mend = cast(immutable ModuleInfo**)&__stop_minfo;
_sections.moduleGroup = ModuleGroup(mbeg[0 .. mend - mbeg]);

auto pbeg = cast(void*)&etext;
auto pend = cast(void*)&_end;
Expand Down Expand Up @@ -148,47 +151,17 @@ ref void[] getTLSBlockAlloc()

__gshared SectionGroup _sections;

// This linked list is created by a compiler generated function inserted
// into the .ctor list by the compiler.
struct ModuleReference
{
ModuleReference* next;
ModuleInfo* mod;
}

extern (C) __gshared immutable(ModuleReference*) _Dmodule_ref; // start of linked list

immutable(ModuleInfo*)[] getModuleInfos()
out (result)
{
foreach(m; result)
assert(m !is null);
}
body
{
size_t len;
immutable(ModuleReference)* mr;

for (mr = _Dmodule_ref; mr; mr = mr.next)
len++;
auto result = (cast(immutable(ModuleInfo)**).malloc(len * size_t.sizeof))[0 .. len];
len = 0;
for (mr = _Dmodule_ref; mr; mr = mr.next)
{ result[len] = mr.mod;
len++;
}
return cast(immutable)result;
}

extern(C)
{
/* Symbols created by the compiler/linker and inserted into the
* object file that 'bracket' sections.
*/
extern __gshared
{
void* _deh_beg;
void* _deh_end;
void* __start_deh;
void* __stop_deh;
void* __start_minfo;
void* __stop_minfo;

size_t etext;
size_t _end;
Expand Down
46 changes: 9 additions & 37 deletions src/rt/sections_solaris.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct SectionGroup

@property immutable(FuncTable)[] ehTables() const
{
auto pbeg = cast(immutable(FuncTable)*)&_deh_beg;
auto pend = cast(immutable(FuncTable)*)&_deh_end;
auto pbeg = cast(immutable(FuncTable)*)&__start_deh;
auto pend = cast(immutable(FuncTable)*)&__stop_deh;
return pbeg[0 .. pend - pbeg];
}

Expand All @@ -58,7 +58,9 @@ private:

void initSections()
{
_sections.moduleGroup = ModuleGroup(getModuleInfos());
auto mbeg = cast(immutable ModuleInfo**)&__start_minfo;
auto mend = cast(immutable ModuleInfo**)&__stop_minfo;
_sections.moduleGroup = ModuleGroup(mbeg[0 .. mend - mbeg]);

auto pbeg = cast(void*)&__dso_handle;
auto pend = cast(void*)&_end;
Expand Down Expand Up @@ -90,47 +92,17 @@ private:

__gshared SectionGroup _sections;

// This linked list is created by a compiler generated function inserted
// into the .ctor list by the compiler.
struct ModuleReference
{
ModuleReference* next;
ModuleInfo* mod;
}

extern (C) __gshared immutable(ModuleReference*) _Dmodule_ref; // start of linked list

immutable(ModuleInfo*)[] getModuleInfos()
out (result)
{
foreach(m; result)
assert(m !is null);
}
body
{
size_t len;
immutable(ModuleReference)* mr;

for (mr = _Dmodule_ref; mr; mr = mr.next)
len++;
auto result = (cast(immutable(ModuleInfo)**).malloc(len * size_t.sizeof))[0 .. len];
len = 0;
for (mr = _Dmodule_ref; mr; mr = mr.next)
{ result[len] = mr.mod;
len++;
}
return cast(immutable)result;
}

extern(C)
{
/* Symbols created by the compiler/linker and inserted into the
* object file that 'bracket' sections.
*/
extern __gshared
{
void* _deh_beg;
void* _deh_end;
void* __start_deh;
void* __stop_deh;
void* __start_minfo;
void* __stop_minfo;
int __dso_handle;
int _end;
}
Expand Down

0 comments on commit 0df48a5

Please sign in to comment.