From da073b03cf173aa3f0d80c303201c750bc40a082 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Wed, 6 Mar 2013 09:46:28 +0100 Subject: [PATCH] use EH tables from SectionGroup --- src/rt/deh2.d | 47 +++++++++++++-------------------------- src/rt/memory_osx.d | 10 --------- src/rt/sections.d | 3 ++- src/rt/sections_freebsd.d | 18 ++++++++++++++- src/rt/sections_linux.d | 12 +++++----- src/rt/sections_osx.d | 20 ++++++++++++++++- src/rt/sections_solaris.d | 16 +++++++++++++ src/rt/sections_win64.d | 18 ++++++++++++++- 8 files changed, 93 insertions(+), 51 deletions(-) diff --git a/src/rt/deh2.d b/src/rt/deh2.d index 9d6e5316830..3b3854206d3 100644 --- a/src/rt/deh2.d +++ b/src/rt/deh2.d @@ -31,23 +31,6 @@ debug(PRINTF) import core.stdc.stdio : printf; extern (C) { - version (OSX) - { - // Set by rt.memory_osx.onAddImage() - __gshared ubyte[] _deh_eh_array; - } - else - { - extern __gshared - { - /* Symbols created by the compiler and inserted into the object file - * that 'bracket' the __deh_eh segment - */ - void* _deh_beg; - void* _deh_end; - } - } - Throwable.TraceInfo _d_traceContext(void* ptr = null); int _d_isbaseof(ClassInfo oc, ClassInfo c); @@ -128,21 +111,23 @@ void terminate() * Return DHandlerTable if there is one, NULL if not. */ -FuncTable *__eh_finddata(void *address) +immutable(FuncTable)* __eh_finddata(void *address) { - debug(PRINTF) printf("FuncTable.sizeof = %p\n", FuncTable.sizeof); - debug(PRINTF) printf("__eh_finddata(address = %p)\n", address); - - version (OSX) - { - auto pstart = cast(FuncTable *)_deh_eh_array.ptr; - auto pend = cast(FuncTable *)(_deh_eh_array.ptr + _deh_eh_array.length); - } - else + import rt.sections; + foreach (ref sg; SectionGroup) { - auto pstart = cast(FuncTable *)&_deh_beg; - auto pend = cast(FuncTable *)&_deh_end; + auto pstart = sg.ehTables.ptr; + auto pend = pstart + sg.ehTables.length; + if (auto ft = __eh_finddata(address, pstart, pend)) + return ft; } + return null; +} + +immutable(FuncTable)* __eh_finddata(void *address, immutable(FuncTable)* pstart, immutable(FuncTable)* pend) +{ + debug(PRINTF) printf("FuncTable.sizeof = %p\n", FuncTable.sizeof); + debug(PRINTF) printf("__eh_finddata(address = %p)\n", address); debug(PRINTF) printf("_deh_beg = %p, _deh_end = %p\n", pstart, pend); for (auto ft = pstart; 1; ft++) @@ -159,7 +144,7 @@ FuncTable *__eh_finddata(void *address) */ if (ft.fptr == null) { - ft = cast(FuncTable *)(cast(void**)ft + 1); + ft = cast(immutable(FuncTable)*)(cast(void**)ft + 1); goto Lagain; } } @@ -167,7 +152,7 @@ FuncTable *__eh_finddata(void *address) debug(PRINTF) printf(" ft = %p, fptr = %p, handlertable = %p, fsize = x%03x\n", ft, ft.fptr, ft.handlertable, ft.fsize); - void *fptr = ft.fptr; + immutable(void)* fptr = ft.fptr; version (Win64) { /* If linked with /DEBUG, the linker rewrites it so the function pointer points diff --git a/src/rt/memory_osx.d b/src/rt/memory_osx.d index 5eb33abbd21..dd7a84ea741 100644 --- a/src/rt/memory_osx.d +++ b/src/rt/memory_osx.d @@ -18,7 +18,6 @@ version(OSX): import src.core.sys.osx.mach.dyld; import src.core.sys.osx.mach.getsect; -extern (C) extern __gshared ubyte[] _deh_eh_array; extern (C) extern __gshared ubyte[][2] _tls_data_array; extern (C) void gc_addRange( void* p, size_t sz ); @@ -86,15 +85,6 @@ extern (C) void onAddImage(in mach_header* h, intptr_t slide) if (auto sect = getSection(h, slide, e.seg.ptr, e.sect.ptr)) gc_addRange(sect.ptr, sect.length); } - - if (auto sect = getSection(h, slide, "__DATA", "__deh_eh")) - { - //printf(" deh_eh\n"); - /* BUG: this will fail if there are multiple images with __deh_eh - * sections. Not set up to handle that. - */ - _deh_eh_array = sect.ptr[0 .. sect.length]; - } } diff --git a/src/rt/sections.d b/src/rt/sections.d index e4b0797b82e..cd8e4215c42 100644 --- a/src/rt/sections.d +++ b/src/rt/sections.d @@ -23,13 +23,14 @@ else version (Win64) else static assert(0, "unimplemented"); -import rt.minfo; +import rt.deh2, rt.minfo; template isSectionGroup(T) { enum isSectionGroup = is(typeof(T.init.modules) == ModuleInfo*[]) && is(typeof(T.init.moduleGroup) == ModuleGroup) && + (!is(typeof(T.init.ehTables)) || is(typeof(T.init.ehTables) == immutable(FuncTable)[])) && is(typeof({ foreach (ref T; T) {}})) && is(typeof({ foreach_reverse (ref T; T) {}})); } diff --git a/src/rt/sections_freebsd.d b/src/rt/sections_freebsd.d index 942dcf02b5c..c2a0d5c7fdd 100644 --- a/src/rt/sections_freebsd.d +++ b/src/rt/sections_freebsd.d @@ -15,7 +15,7 @@ version (FreeBSD): // debug = PRINTF; debug(PRINTF) import core.stdc.stdio; import core.stdc.stdlib : malloc, free; -import rt.minfo; +import rt.deh2, rt.minfo; struct SectionGroup { @@ -39,6 +39,13 @@ struct SectionGroup return _moduleGroup; } + @property immutable(FuncTable)[] ehTables() const + { + auto pbeg = cast(immutable(FuncTable)*)&_deh_beg; + auto pend = cast(immutable(FuncTable)*)&_deh_end; + return pbeg[0 .. pend - pbeg]; + } + private: ModuleGroup _moduleGroup; } @@ -88,3 +95,12 @@ body } return result; } + +extern(C) +{ + /* Symbols created by the compiler and inserted into the object file + * that 'bracket' the __deh_eh segment + */ + extern __gshared void* _deh_beg; + extern __gshared void* _deh_end; +} diff --git a/src/rt/sections_linux.d b/src/rt/sections_linux.d index 6be954e8444..e6e2ea5e9b1 100644 --- a/src/rt/sections_linux.d +++ b/src/rt/sections_linux.d @@ -54,9 +54,9 @@ struct DSO return _moduleGroup; } - @property inout(FuncTable)[] ehtables() inout + @property immutable(FuncTable)[] ehTables() const { - return _ehtables[]; + return _ehTables[]; } @property inout(void[])[] gcRanges() inout @@ -77,8 +77,8 @@ private: assert(_tlsMod || !_tlsSize); } - FuncTable[] _ehtables; - ModuleGroup _moduleGroup; + immutable(FuncTable)[] _ehTables; + ModuleGroup _moduleGroup; Array!(void[]) _gcRanges; size_t _tlsMod; size_t _tlsSize; @@ -120,7 +120,7 @@ struct CompilerDSOData size_t _version; void** _slot; // can be used to store runtime data object.ModuleInfo** _minfo_beg, _minfo_end; - rt.deh2.FuncTable* _deh_beg, _deh_end; + immutable(rt.deh2.FuncTable)* _deh_beg, _deh_end; } T[] toRange(T)(T* beg, T* end) { return beg[0 .. end - beg]; } @@ -139,7 +139,7 @@ extern(C) void _d_dso_registry(CompilerDSOData* data) *data._slot = pdso; // store backlink in library record pdso._moduleGroup = ModuleGroup(toRange(data._minfo_beg, data._minfo_end)); - pdso._ehtables = toRange(data._deh_beg, data._deh_end); + pdso._ehTables = toRange(data._deh_beg, data._deh_end); dl_phdr_info info = void; findDSOInfoForAddr(data._slot, &info) || assert(0); diff --git a/src/rt/sections_osx.d b/src/rt/sections_osx.d index ed069b6ff70..791de325609 100644 --- a/src/rt/sections_osx.d +++ b/src/rt/sections_osx.d @@ -17,7 +17,7 @@ version(OSX): // debug = PRINTF; debug(PRINTF) import core.stdc.stdio; import core.stdc.stdlib : malloc, free; -import rt.minfo; +import rt.deh2, rt.minfo; import rt.memory_osx; import src.core.sys.osx.mach.dyld; import src.core.sys.osx.mach.getsect; @@ -44,7 +44,13 @@ struct SectionGroup return _moduleGroup; } + @property immutable(FuncTable)[] ehTables() const + { + return _ehTables[]; + } + private: + immutable(FuncTable)[] _ehTables; ModuleGroup _moduleGroup; } @@ -74,4 +80,16 @@ extern (C) void sections_osx_onAddImage(in mach_header* h, intptr_t slide) _sections._moduleGroup = ModuleGroup(p[0 .. len]); } + + if (auto sect = getSection(h, slide, "__DATA", "__deh_eh")) + { + // no support for multiple images yet + _sections._ehTables.ptr is null || assert(0); + + debug(PRINTF) printf(" deh_eh\n"); + auto p = cast(immutable(FuncTable)*)sect.ptr; + immutable len = sect.length / (*p).sizeof; + + _sections._ehTables = p[0 .. len]; + } } diff --git a/src/rt/sections_solaris.d b/src/rt/sections_solaris.d index 7995d29f95c..ade74fe5d1e 100644 --- a/src/rt/sections_solaris.d +++ b/src/rt/sections_solaris.d @@ -39,6 +39,13 @@ struct SectionGroup return _moduleGroup; } + @property immutable(FuncTable)[] ehTables() const + { + auto pbeg = cast(immutable(FuncTable)*)&_deh_beg; + auto pend = cast(immutable(FuncTable)*)&_deh_end; + return pbeg[0 .. pend - pbeg]; + } + private: ModuleGroup _moduleGroup; } @@ -88,3 +95,12 @@ body } return result; } + +extern(C) +{ + /* Symbols created by the compiler and inserted into the object file + * that 'bracket' the __deh_eh segment + */ + extern __gshared void* _deh_beg; + extern __gshared void* _deh_end; +} diff --git a/src/rt/sections_win64.d b/src/rt/sections_win64.d index 754e45c8ba8..4886b5ac393 100644 --- a/src/rt/sections_win64.d +++ b/src/rt/sections_win64.d @@ -17,7 +17,7 @@ version(Win64): // debug = PRINTF; debug(PRINTF) import core.stdc.stdio; import core.stdc.stdlib : malloc, free; -import rt.minfo; +import rt.deh2, rt.minfo; struct SectionGroup { @@ -41,6 +41,13 @@ struct SectionGroup return _moduleGroup; } + @property immutable(FuncTable)[] ehTables() const + { + auto pbeg = cast(immutable(FuncTable)*)&_deh_beg; + auto pend = cast(immutable(FuncTable)*)&_deh_end; + return pbeg[0 .. pend - pbeg]; + } + private: ModuleGroup _moduleGroup; } @@ -95,3 +102,12 @@ body return result; } + +extern(C) +{ + /* Symbols created by the compiler and inserted into the object file + * that 'bracket' the __deh_eh segment + */ + extern __gshared void* _deh_beg; + extern __gshared void* _deh_end; +}