Skip to content

fix #18202 - string literals used as pointers aren't pooled/merged - #24363

Open
zxan wants to merge 1 commit into
dlang:masterfrom
zxan:fix18202-toStringSymbol
Open

zxan wants to merge 1 commit into
dlang:masterfrom
zxan:fix18202-toStringSymbol

Conversation

@zxan

@zxan zxan commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #18202.

The ELF section flags were fixed earlier, but literals used as pointers never reached the mergeable section. visitString lowered the Tpointer case to OPstring, which the backend pools separately and writes into plain .rodata, so "hello" and "hello".ptr were two copies at two addresses even within a single module.

Use toStringSymbol for pointers too, which is what Mach-O AArch64 already did. Nothing else depends on OPstring: the only folds keyed on it rewrite strcpy/strcmp, which the frontend never generates.

toStringSymbol also needed fixing. It pooled on the raw bytes without the code unit size, so "", ""w and ""d shared one symbol and whichever was emitted first decided the terminator width. That was harmless while only arrays used the pool, since arrays carry their length and never read the terminator, but it breaks pointers. The key now includes sz.

Comment thread compiler/src/dmd/glue/e2ir.d Resolved
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

DMD perf check

Metric Base PR Δ
compile Phobos codegen (instr) 1,421.3 M 1,425.0 M +0.258%
compile vibe.d (instr) 13,583.2 M 13,600.8 M +0.129%
All measurements
Metric Base PR Δ
compile hello.d (instr) 204.6 M 204.6 M -0.006%
compile hello.d -O -release (instr) 222.2 M 222.2 M -0.011%
compile Phobos (instr) 4,719.4 M 4,723.1 M +0.079%
compile Phobos codegen (instr) 1,421.3 M 1,425.0 M +0.258%
compile vibe.d (instr) 13,583.2 M 13,600.8 M +0.129%
compile ctRegex tests (instr) 29,493.5 M 29,497.5 M +0.014%
dmd binary size (stripped) 8.18 MB 8.18 MB -0.05%
hello binary size (stripped) 0.72 MB 0.72 MB 0.00%
peak RSS (compile hello.d) 42.63 MB 42.54 MB -0.21%
peak RSS (compile Phobos) 605.7 MB 605.6 MB -0.01%
peak RSS (compile vibe.d) 1865 MB 1865 MB 0.00%
peak RSS (compile ctRegex tests) 2033 MB 2033 MB +0.01%
page faults (compile hello.d) 8,844 8,845 +0.01%
page faults (compile Phobos) 153,157 153,167 +0.01%
page faults (compile vibe.d) 476,175 476,186 0.00%
page faults (compile ctRegex tests) 518,549 518,548 0.00%
compile dmd itself (wall) 13.9 s 13.9 s +0.28%
compile ctRegex tests (wall) 4,662 ms 4,631 ms -0.68%
compile hello.d (wall) 65.1 ms 63.9 ms -1.84%
compile Phobos (wall) 1,477 ms 1,474 ms -0.18%

d1ba7a2 vs merge-base f5a2e5c · about these metrics · historical dashboard

@zxan
zxan force-pushed the fix18202-toStringSymbol branch from 235d015 to 40db340 Compare November 16, 2026 07:35

@thewilsonator thewilsonator left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise looks good

Comment thread compiler/src/dmd/glue/e2ir.d Resolved
Comment thread compiler/src/dmd/glue/e2ir.d Resolved
@zxan
zxan force-pushed the fix18202-toStringSymbol branch from 40db340 to 9952963 Compare November 16, 2026 11:50
Comment thread compiler/src/dmd/glue/e2ir.d Resolved
@zxan
zxan force-pushed the fix18202-toStringSymbol branch 3 times, most recently from 0bbb62a to 46527a0 Compare November 23, 2026 20:22
@zxan
zxan force-pushed the fix18202-toStringSymbol branch from 46527a0 to d1ba7a2 Compare November 25, 2026 12:31
Comment on lines +19 to +20
auto w8 = cast(long[1])"abcdefgh"c;
assert(w8[0] == 0x6867_6665_6463_6261);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this dependant on byte order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is, thanks for catching, should I switch back to reading bytes back as char?

@zxan zxan Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace it with this?

    auto w8 = cast(long[1])"abcdefgh"c;
    auto w8b = cast(const(char)*)w8.ptr;
    foreach (i; 0 .. 8)
        assert(w8b[i] == 'a' + i);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String literals not merged by linker because of wrong ELF output

3 participants