Thread overview
[Issue 3956] New: linker removes underscore from all exported symbols of a module but the first
Mar 13, 2010
Rainer Schuetze
Dec 31, 2011
Rainer Schuetze
Sep 28, 2013
Martin Nowak
Sep 28, 2013
Martin Nowak
Sep 28, 2013
Martin Nowak
Sep 28, 2013
Martin Nowak
Sep 28, 2013
Martin Nowak
March 13, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3956

           Summary: linker removes underscore from all exported symbols of
                    a module but the first
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optlink
        AssignedTo: nobody@puremagic.com
        ReportedBy: r.sagitario@gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario@gmx.de> 2010-03-13 09:18:09 PST ---
this test program:

module testexport;

export void foo1() {}
export void foo2() {}
export void foo3() {}

void main() {}

compiles, but exports in the resulting executable (not a DLL here for
simplicity) are wrong.

>dumpbin /exports testexport.exe
[...]
    ordinal hint RVA      name

          1    0 00003014 D10testexport4foo2FZv
          2    1 00003018 D10testexport4foo3FZv
          3    2 00003010 _D10testexport4foo1FZv
[...]

The object file seems ok, here's a snippet from obj2asms' output:

    extrn    _D10testexport4foo1FZv
    ;expdef expflag=x00, export '_D10testexport4foo1FZv', internal '',
ordinal=x0
    extrn    _D10testexport4foo2FZv
    ;expdef expflag=x00, export '_D10testexport4foo2FZv', internal '',
ordinal=x0
    extrn    _D10testexport4foo3FZv
    ;expdef expflag=x00, export '_D10testexport4foo3FZv', internal '',
ordinal=x0
[...]
    public    _D10testexport12__ModuleInfoZ
_D10testexport4foo1FZv    COMDAT flags=x0 attr=x0 align=x0
_D10testexport4foo2FZv    COMDAT flags=x0 attr=x0 align=x0
_D10testexport4foo3FZv    COMDAT flags=x0 attr=x0 align=x0
__Dmain    COMDAT flags=x0 attr=x0 align=x0

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3956


Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> 2011-12-31 01:11:55 PST ---
*** Issue 7186 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: -------
September 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3956


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |dll
                 CC|                            |code@dawg.eu
           Severity|normal                      |major


--- Comment #2 from Martin Nowak <code@dawg.eu> 2013-09-27 19:05:26 PDT ---
This just broke my shiny new loadFunc, loadSym implementation and it took me +1h to get here. Any ideas how to fix this?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3956



--- Comment #3 from Martin Nowak <code@dawg.eu> 2013-09-27 22:17:47 PDT ---
Presumably something in this TWEAK_EXPORT_NAMES function goes wrong or the function isn't called under certain circumstances. It seems simple enough to remove the underscore striping altogether. Is it possible to debug optlink with some debug infos. How to build this thing?

https://github.com/DigitalMars/optlink/blob/475bc5c1fa28eaf899ba4ac1dcfe2ab415db16c6/common/coment.asm#L529

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3956



--- Comment #4 from Martin Nowak <code@dawg.eu> 2013-09-28 07:25:41 PDT ---
#ifdef fg_pe

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3956



--- Comment #5 from Martin Nowak <code@dawg.eu> 2013-09-28 07:45:37 PDT ---
YES_EXPORT PROC
;; ...
#ifdef fg_pe
   if (OUTPUT_PE) // false on first test
      TWEAK_EXPORT_NAMES();
#endif
    DEFINE_EXPORT(); // could set ANY_USE32, but it's usually already
    SELECT_OUTPUT_SEGMENTED_OR_PE();
;; ...
YES_EXPORT ENDP

SELECT_OUTPUT_SEGMENTED_OR_PE PROC
    if (!(OUTPUT_SEGMENTED | OUTPUT_PE))
       return;
    if (ANY_USE32) // this is already set by defining the output segments
        SELECT_OUTPUT_PE(); // sets OUTPUT_PE
    else
        SELECT_OUTPUT_SEGMENTED();
SELECT_OUTPUT_SEGMENTED_OR_PE ENDP

I found the bug, thanks to OllyDbg, but I could use some help to interpret and
resolve it.
From what I understand optlink determines the output format OUTPUT_SEGMENTED or
OUTPUT_PE depending on the input files. That is when it first encounters some
usage of 32-bit symbols it will set ANY_USE32.
Striping the leading underscore in the exported name is only done for
OUTPUT_PE.
The problem comes from the circular dependency in the OUTPUT_PE test above. For
the first export symbol no output format has yet been set, thus the test fails
and the symbol is not stripped.

One way to resolve this would be to prematurely test for ANY_USE32 if no OUTPUT is selected.

    if (OUTPUT_PE || !OUTPUT_SEGMENTED && ANY_USE32)


Any ideas?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 28, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3956


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #6 from Martin Nowak <code@dawg.eu> 2013-09-28 13:28:54 PDT ---
https://github.com/DigitalMars/optlink/pull/10

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