Bug 23011 – importC: asm label to set symbol name doesn't work with externs

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2022-04-13T16:33:44Z
Last change time
2022-04-18T13:34:29Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
duser
See also
https://issues.dlang.org/show_bug.cgi?id=23012

Attachments

IDFilenameSummaryContent-TypeSize
1845manglefix.patchfixtext/plain1027

Comments

Comment #0 by duser — 2022-04-13T16:33:44Z
runnable example (that currently fails): extern char **myenviron asm("environ"); int myprintf(char *, ...) asm("printf"); int main() { void *p = &myenviron; myprintf("%p\n", p); return 0; } works with gcc/clang, gives a link error with dmd /usr/bin/ld: test.o: in function `main': test.c:(.text.main[main]+0x7): undefined reference to `myenviron' /usr/bin/ld: test.c:(.text.main[main]+0x18): undefined reference to `myprintf' collect2: error: ld returned 1 exit status Error: linker exited with status 1 it should be linking with the names given in asm()
Comment #1 by duser — 2022-04-13T18:46:12Z
Created attachment 1845 fix
Comment #2 by bugzilla — 2022-04-15T09:31:35Z
gcc/clang's asm extension is ignored by ImportC. There isn't any reasonable way I can think of to support it, as that would require creating the gcc/clang assembler.
Comment #3 by duser — 2022-04-15T09:52:20Z
there is limited support for asm() in importC to use it like pragma(mangle), added for issue 21934 this wasn't documented on the importC spec page so i only found out about it when reading the C parser source https://github.com/dlang/dmd/blob/0e3e0f9/src/dmd/cparse.d#L1845 glibc headers use asm() this way to redirect some functions based on feature macros (like whether off_t should be 64 bits on 32-bit, or whether non-standard GNU versions of some functions should be used) - if the asm() is ignored, it might silently link against the wrong function
Comment #4 by dlang-bot — 2022-04-18T07:36:00Z
@WalterBright created dlang/dmd pull request #14008 "fix Issue 23011 - importC: asm label to set symbol name doesn't work …" fixing this issue: - fix Issue 23011 - importC: asm label to set symbol name doesn't work with externs https://github.com/dlang/dmd/pull/14008
Comment #5 by dlang-bot — 2022-04-18T13:34:29Z
dlang/dmd pull request #14008 "fix Issue 23011 - importC: asm label to set symbol name doesn't work …" was merged into master: - 59d7f078ecfcfed2f77e391a4f8f92ffc45b73a0 by Walter Bright: fix Issue 23011 - importC: asm label to set symbol name doesn't work with externs https://github.com/dlang/dmd/pull/14008