www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24286] New: String literals not merged by linker because of

https://issues.dlang.org/show_bug.cgi?id=24286

          Issue ID: 24286
           Summary: String literals not merged by linker because of wrong
                    ELF output
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

When compiled separately, the following succeeds with LDC but fails with DMD on
linux:

```D
extern(C) string getHello() { return "hello"; }
```


```D
extern(C) string getHello();

void main()
{
    assert(getHello.ptr == "hello".ptr);
}
```

The reasons is that DMD generates invalid string sections, which have SHF_MERGE
| SHF_STRINGS but sh_entisze = 0 instead of char.sizeof. See:
https://github.com/dlang/dmd/pull/15915

--
Dec 18 2023