[Issue 879] New: support for --gc-sections

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 23 15:28:21 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=879

           Summary: support for --gc-sections
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: thomas-dloop at kuehne.cn


--gc-sections is ld's flag to "Enable garbage collection of unused input 
sections."

As known(#100 and #101) it currently breaks DMD's exception handling on Linux. 
I think I've found the cause and know a simple fix.

#
# void main(){
#    throw new Exception("message");
# }
#

dmd a.d -ofa; nm --numeric-sort a
[...]
> 000000000805c4b0 R _D3std6thread6Thread6__vtblZ
> 000000000805c508 R _deh_beg
> 000000000805c508 r _TMP3
> 000000000805c514 r _TMP1
[...]
> 000000000805c604 r _TMP14
> 000000000805c610 r _TMP27
> 000000000805c61c R _deh_end
> 000000000805c61c r __FRAME_END__
[...]

dmd a.d -ofa -L--gc-sections; nm --numeric-sort a
> [...]
> 0000000008053270 R _D3std6thread6Thread6__vtblZ
> 00000000080532c8 R _deh_beg
> 00000000080532c8 R _deh_end
> 00000000080532c8 r __FRAME_END__
> [...]

The missing _TMP... symbols are of type internal.deh2.FuncTable and describe 
where to find the exception handlers of a given function.

BUG 1:
ld rightfully removed those as they are never directly referenced. However they 
are accessed indirectly via _deh_beg and _deh_end (-> internal/deh2.d:98-100).

FIX 1:
Define an elf symbol with the following characteristics:
address:  _deh_beg
size: _deh_end - _deh_beg + sizeof(_deh_end)
and ensure that this symbol is guaranteed to be referenced somewhere regardless 
of compiler flags like -O, -release and -inline.

BUG 2:
from above:
> 00000000080532c8 R _deh_beg
> 00000000080532c8 R _deh_end
> 00000000080532c8 r __FRAME_END__
_deh_beg, _deh_end and __FRAME_END__ have the same addresses because _deh_beg 
and _deh_end claim to be of size zero.

FIX 2:
The same as #472, please emit correct size information for all elf symbols.


-- 



More information about the Digitalmars-d-bugs mailing list