www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 879] New: support for --gc-sections

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: thomas-dloop 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__

and _deh_end claim to be of size zero. FIX 2: The same as #472, please emit correct size information for all elf symbols. --
Jan 23 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=879





------- Comment #1 from thomas-dloop kuehne.cn  2007-03-31 15:08 -------
Created an attachment (id=106)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=106&action=view)
Binutils workaround


-- 
Mar 31 2007
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=879





------- Comment #2 from thomas-dloop kuehne.cn  2007-04-04 15:39 -------
Daniel Jacobowitz suggested a much more straight forward solution on the 
binutils mailing list(http://sourceware.org/ml/binutils/):

 Another way to fix this would be to emit R_arch_NONE relocations from
 the code sections to the EH tables they require.

--
Apr 04 2007
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
d-bugmail puremagic.com wrote:
 ------- Comment #2 from thomas-dloop kuehne.cn  2007-04-04 15:39 -------
 Daniel Jacobowitz suggested a much more straight forward solution on the 
 binutils mailing list(http://sourceware.org/ml/binutils/):
 
 Another way to fix this would be to emit R_arch_NONE relocations from
 the code sections to the EH tables they require.


Interesting. And should be easy enough to implement. An added advantage to this approach would be that no relatively new version of binutils will be required to use --gc-sections[1], which might require working around (Linux) package managers. It'd just a recent version of DMD (after this is implemented) which is more likely to be manually installed (and frequently updated) anyway. [1]: (Assuming R_arch_NONE isn't a recent feature)
Apr 04 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=879





------- Comment #4 from thomas-dloop kuehne.cn  2007-04-25 12:56 -------
Walter, are you going to implement the R_arch_NONE solution or should we patch 
binutils?


-- 
Apr 25 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=879


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg gmail.com


--- Comment #5 from Brad Roberts <braddr puremagic.com> 2010-08-29 12:35:37 PDT
---
*** Issue 4758 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 29 2010