Issue 24340 - Invalid export directives generated
Summary: Invalid export directives generated
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P1 blocker
Assignee: No Owner
URL:
Keywords: dll, pull
Depends on:
Blocks:
 
Reported: 2024-01-15 18:21 UTC by Richard (Rikki) Andrew Cattermole
Modified: 2024-01-17 09:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Richard (Rikki) Andrew Cattermole 2024-01-15 18:21:11 UTC
I'm testing Rainer's freshly pulled shared library PR.

It is not linking with visibility turned on to public.

I am getting invalid export directives being generated. Of note:

```
   /EXPORT:_D4core8internal8lifetime__T10emplaceRefTS6sidero4base10containers13readonlyslice__T5SliceThZQj8IteratorTQCmTiTSQCsQCo10allocators3api11RCAllocatorTAxhZQEuFKQEmKiKQCaKQtZ1S__T6__ctorZQiMFNaNbNcNiNfKiKQDlKQCeZSQHzQHxQHr__TQHlTQHcTQHgTiTQEuTQDnZQIhFKQHzKiKQFnKQEgZQDo
   /EXPORT:
   /EXPORT:_D6object__T10RTInfoImplVAmA3i592i5063812098665367111i70ZQBtyG3m
   /EXPORT:_D4core8internal5array8equality__T8__equalsTtTiZQoFNaNbNiNeMxAtMxAiZb
   /EXPORT:_D4core8internal5array8equality__T7isEqualTtTiZQnFNaNbNiMxPtMxPimZb
   /EXPORT:_D6object__T10RTInfoImplVAmA2i336i301826721351ZQBjyG2m
   /EXPORT:_D6object__T10RTInfoImplVAmA2i208i4605511ZQBeyG2m
   /EXPORT:n
   wP
   /EXPORT:n
   wð
   /EXPORT:_D6object__T10RTInfoImplVAmA9i3920i5063812098665367111i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i301826721350ZQGuyG9m
```

The other ~30k exports look ok.

Error:

```
sidero_base-test-unittest.obj : fatal error LNK1276: invalid directive 'wP' found; does not start with '/'
Error: linker exited with status 1276
       C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\link.exe /NOLOGO "C:\Users\alpha\AppData\Local\dub\cache\sidero_base\~master\build\sidero_base-test-unittest-unittest-f2Z24g5qpSiOgu5uMwz-ZA\sidero_base-test-unittest.obj" /OUT:"C:\Users\alpha\AppData\Local\dub\cache\sidero_base\~master\build\sidero_base-test-unittest-unittest-f2Z24g5qpSiOgu5uMwz-ZA\sidero_base-test-unittest.exe"  /DEFAULTLIB:"Ws2_32.lib" /DEFAULTLIB:"advapi32.lib" /DEFAULTLIB:"Userenv.lib" /DEFAULTLIB:phobos64 /DEBUG /IGNORE:4217 /FORCE:MULTIPLE  /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.20348.0\um\x64"
```

Directives were dumped via MSVC ``dumpbin /DIRECTIVES sidero_base-test-unittest.obj > directives.txt 2>&1``
Comment 1 Richard (Rikki) Andrew Cattermole 2024-01-15 19:11:14 UTC
I have been able to identify the exports that are not showing up.

```
_D6object__T10RTInfoImplVAmA81i40880i1808504320951916831i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i1808504320951916825i7234017283807670553i7234017283807667300i7234017283807667300i7234017283807667300i7234017283807667300i7234017283807667300i7234017283807667300i1236282250650724ZQCKkyG81m
```

```
_D6object__T10RTInfoImplVAmA77i38480i5063812098665367111i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i70ZQCGuyG77m
```

```
_D6object__T10RTInfoImplVAmA74i36944i5063812098665367111i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i5063812098665367110i70ZQCEmyG74m
```

I modified MsCoffObj_export_symbol to print destr in the region of exports (by a simple counter since its all ordered) and used exports surrounding to confirm. https://github.com/dlang/dmd/blob/6da8f7266ca1cafbc1050413457a9eee015d5f05/compiler/src/dmd/backend/mscoffobj.d#L1746

Printing the lengths (strlen) of destr and and dest.ptr lead to the outputs:

6 instead of 1643
6 instead of 1549
6 instead of 1489

The problem appears to be the stack buffer for using DEST_LEN which has the order of 900 values as per https://github.com/dlang/dmd/blob/6da8f7266ca1cafbc1050413457a9eee015d5f05/compiler/src/dmd/backend/cc.d#L83

Fix incoming.
Comment 2 Dlang Bot 2024-01-15 19:16:37 UTC
@rikkimax created dlang/dmd pull request #16047 "Fix issue 24340 - Invalid export directives generated" fixing this issue:

- Fix issue 24340 - Invalid export directives generated

https://github.com/dlang/dmd/pull/16047
Comment 3 Dlang Bot 2024-01-15 19:16:38 UTC
@rikkimax updated dlang/dmd pull request #16047 "Fix issue 24340 - Invalid export directives generated" fixing this issue:

- Fix issue 24340 - Invalid export directives generated

https://github.com/dlang/dmd/pull/16047