Issue 24286 - String literals not merged by linker because of wrong ELF output
Summary: String literals not merged by linker because of wrong ELF output
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2023-12-18 11:55 UTC by Dennis
Modified: 2023-12-18 12:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2023-12-18 11:55:31 UTC
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
Comment 1 Dlang Bot 2023-12-18 12:03:12 UTC
@dkorpel created dlang/dmd pull request #15922 "Fix 24286 - String literals not merged by linker because of wrong ELF output" fixing this issue:

- Fix 24286 - String literals not merged by linker because of wrong ELF output

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