Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

rt.config: Compatibility with GDC '-fno-weak-templates' option #3716

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Jan 30, 2022

  1. rt.config: Compatibility with GDC '-fno-weak-templates' option

    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
    ssvb committed Jan 30, 2022
    Configuration menu
    Copy the full SHA
    a88b44e View commit details
    Browse the repository at this point in the history