From e91f59d2175c1056af5d2de59f4fd5dee7a1779d Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Sun, 6 Sep 2015 20:22:26 +0200 Subject: [PATCH] use linker generated section brackets --- src/rt/sections_android.d | 47 +++++++++------------------------------ src/rt/sections_solaris.d | 46 ++++++++------------------------------ 2 files changed, 19 insertions(+), 74 deletions(-) diff --git a/src/rt/sections_android.d b/src/rt/sections_android.d index 4fd4a440d0..2c76fe59cc 100644 --- a/src/rt/sections_android.d +++ b/src/rt/sections_android.d @@ -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]; } @@ -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; @@ -148,38 +151,6 @@ 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 @@ -187,8 +158,10 @@ extern(C) */ 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; diff --git a/src/rt/sections_solaris.d b/src/rt/sections_solaris.d index d3e2b64220..31c05fd18f 100644 --- a/src/rt/sections_solaris.d +++ b/src/rt/sections_solaris.d @@ -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]; } @@ -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; @@ -90,38 +92,6 @@ 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 @@ -129,8 +99,10 @@ extern(C) */ 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; }