This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] --gc-sections support for the D compilers DMD and GDC with ELF targets


The below patch adds --gc-sections support for the D compilers DMD
(http://www.digitalmars.com/d) and GDC (http://dgcc.sf.net) to binutils-2.17.

diff -ur binutils-2.17/ld/scripttempl/elf.sc binutils-2.17-dmd-exception/ld/scripttempl/elf.sc
--- binutils-2.17/ld/scripttempl/elf.sc 2005-12-28 07:01:48.000000000 +0100
+++ binutils-2.17-dmd-exception/ld/scripttempl/elf.sc   2007-03-31 19:29:55.000000000 +0200
@@ -371,6 +371,9 @@
   /* Exception handling  */
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+
+  /* DMD / GDC exception handling */
+  .deh_eh     ${RELOCATING-0} :  ONLY_IF_RW { KEEP (*(.deh_eh)) }

   /* Thread Local Storage sections  */
   .tdata       ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }


sample object files with test script:
http://d.puremagic.com/issues/attachment.cgi?bugid=879&action=viewall

The underlying issue:
#
# 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.

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

Thomas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]