www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11199] New: OS X DMD outputs functions to S section, erroneously prevents duplicate symbol error

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

           Summary: OS X DMD outputs functions to S section, erroneously
                    prevents duplicate symbol error
           Product: D
           Version: D2
          Platform: All
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: luis luismarques.eu


--- Comment #0 from Luís Marques <luis luismarques.eu> 2013-10-08 11:29:19 PDT
---
On Linux the following gives out a "multiple definition" error, 
as expected and desired:

    c/test.c:
    void dotest(void) { printf("C\n"); }

    d/test.d:
    extern(C) void dotest() { writeln("D"); }

On OS X no error is flagged, and the C function is always called, 
irrespective of which order I specify the .o files to link. The cause seems to
be OS X DMD (v.2.063.2) outputting the function to the S section:

On Ubuntu:

    $ nm d/test.o | grep dotest; echo "--"; nm c/test.o | grep dotest
    0000000000000000 T dotest
    --
    0000000000000000 T dotest

On OS X:

    $ nm d/test.o | grep dotest; echo "--"; nm c/test.o | grep dotest
    0000000000001490 S _dotest   <-- not in text section, as in Linux
    --
    0000000000000000 T _dotest
    0000000000000060 S _dotest.eh

When using LDC on OS X the linking fails, as expected and desired:

    duplicate symbol _dotest in:
        d/test.o
        c/test.o
    ld: 1 duplicate symbol for architecture x86_64

The LDC .o sections are the same as the C version:

    $ nm d/test.o | grep dotest; echo "--"; nm c/test.o | grep dotest
    0000000000000000 T _dotest
    00000000000000b0 S _dotest.eh
    --
    0000000000000000 T _dotest
    0000000000000060 S _dotest.eh

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 08 2013