-
-
Notifications
You must be signed in to change notification settings - Fork 421
rt.config: Compatibility with GDC '-fno-weak-templates' option #3716
base: master
Are you sure you want to change the base?
Conversation
The rt.config module provides a set of configuration variables, with various ways to override them as documented here: https://dlang.org/phobos/rt_config.html The desirable assembly output for the 'rt_cmdline_enabled' variable looks like this (that's what is now generated by default): .weak rt_cmdline_enabled .data .type rt_cmdline_enabled, @object .size rt_cmdline_enabled, 1 rt_cmdline_enabled: .byte 1 But unfortunately when GDC11 or GDC12 is used with the '-fno-weak-templates' option, the assembly output for the 'rt_cmdline_enabled' variable changes to: .weak rt_cmdline_enabled .section .data.rt_cmdline_enabled,"awG",@progbits,rt_cmdline_enabled,comdat .type rt_cmdline_enabled, @gnu_unique_object .size rt_cmdline_enabled, 1 rt_cmdline_enabled: .byte 1 And this results in "multiple definition of `rt_cmdline_enabled'; /tmp/ccc5MZMh.o:(.bss+0x0): first defined here" linker error when trying to compile the following small program: import std.stdio; extern(C) __gshared bool rt_cmdline_enabled = false; void main(string[] args) { writeln(args); } This patch solves the problem by setting GDC-specific @Attribute("weak") for these variables instead of having them enclosed in a "template { }" block. The assembly output is now always desirable in both '-fweak-templates' and '-fno-weak-templates' configurations. There are very strong reasons to prefer '-fno-weak-templates', because this allows inlining template functions. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102765
Thanks for your pull request and interest in making D better, @ssvb! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + druntime#3716" |
cc @ibuclaw |
This appears to be a little bit more complicated. At least GDC 9/10 versions need to use Another thing is that the bundled copies of druntime in GDC 9/10/11 are missing ae9581c and currently mutilate the command line arguments regardless of the value of the Also GDC 11 is still problematic. I tried to flip the configuration default from '-fweak-templates' to '-fno-weak-templates' in GDC (because fixing template functions inlining is the actual goal), but the compiled toolchain becomes defunct and can't compile applications. The linker complains about missing symbols from Phobos. I'm going to quickly check if reverting all of this '-fweak-templates' / '-fno-weak-templates' stuff in GDC 11/12 back to how it was in GDC 10 may help, but any feedback/advice from @ibuclaw would be very useful. |
You probably want to use Lines 40 to 66 in 348a4ff
CI doesn't check the GDC build (only DMD built with GDC, not GDC building itself), and Iain does manual merges frequently. So whatever you put in |
That's a good point and thanks for the link. The patch can be changed to have no special path for GDC and use I can give it a try. Should I force-push the updated patch to see what the CI says about it?
I actually made a mistake and incorrectly assumed that the As for my earlier comment about
Reverting these 3 patches in GDC 11 does the job and makes template functions inlineable again without any visible problems. |
Looks like the |
LDC should be fine. DMD might still need the template hack for Windows targets. I suggest simply adding the |
ping @ssvb |
@ssvb what is the status of this PR? |
The rt.config module provides a set of configuration variables,
with various ways to override them as documented here:
https://dlang.org/phobos/rt_config.html
The desirable assembly output for the 'rt_cmdline_enabled'
variable looks like this (that's what is now generated by
default):
But unfortunately when GDC11 or GDC12 is used with the
'-fno-weak-templates' option, the assembly output for
the 'rt_cmdline_enabled' variable changes to:
And this results in "multiple definition of `rt_cmdline_enabled';
/tmp/ccc5MZMh.o:(.bss+0x0): first defined here" linker error when
trying to compile the following small program:
This patch solves the problem by setting GDC-specific
@Attribute("weak") for these variables instead of having
them enclosed in a "template { }" block. The assembly output
is now always desirable in both '-fweak-templates' and
'-fno-weak-templates' configurations.
There are very strong reasons to prefer '-fno-weak-templates',
because this allows inlining template functions. See:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102765