Skip to content

Conversation

jacobly0
Copy link
Member

@jacobly0 jacobly0 commented Oct 30, 2023

Depends on #17802
Closes #17678
Closes #17618

@jacobly0 jacobly0 force-pushed the x86_64 branch 2 times, most recently from a4e7be8 to b4c1579 Compare November 2, 2023 15:22
@jacobly0 jacobly0 marked this pull request as ready for review November 2, 2023 15:22
@jacobly0 jacobly0 requested a review from kprotty as a code owner November 2, 2023 15:22
self.rdata_section_index = try self.allocateSection(".rdata", file_size, .{
.CNT_INITIALIZED_DATA = 1,
.MEM_READ = 1,
.MEM_WRITE = 1,
Copy link
Member

Choose a reason for hiding this comment

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

rdata is supposed to be read-only isn't it?

Copy link
Member Author

@jacobly0 jacobly0 Nov 4, 2023

Choose a reason for hiding this comment

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

Due to a linker bug mutable globals are ending up here. I don't understand this enough to open an issue, but @kubkon said to just do this for now.

For reference, the global I ran into this with is lib.test_runner.cmdline_buffer, where the test program would crash on first write to this buffer, and only when the emitted code reaches a certain size (such as enabling n tests, or making unrelated changes to what code is emitted).

Copy link
Member

Choose a reason for hiding this comment

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

It's not rdata, it's .data.rel.ro since we may have pointers inside a struct we lower in that section. The linker code path responsible for selecting output section doesn't do a recursive check for embedded pointers in any linker (macho, elf or coff), and this is important for PIC/PIE targets where the dynamic linker has to slide the address of each pointer within the binary - hence .data.rel.ro which is only writeable during dynamic relocation startup phase - well, in theory at least.

Copy link
Member

Choose a reason for hiding this comment

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

Anyhow, as @jacobly0 mentioned, that was my suggestion to make it writeable to unblock his progress. I am aware of this nuance and will provide a fix in ELF first, and then backport it to other linkers as I start working on them.

@andrewrk
Copy link
Member

andrewrk commented Nov 4, 2023

right-o, well, feel free to merge and save the stuff for follow-up changes if you want

@andrewrk andrewrk merged commit a7d8cd5 into ziglang:master Nov 4, 2023
@jacobly0 jacobly0 deleted the x86_64 branch November 5, 2023 03:22
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.

recent performance regression in the x86 backend on print1mil benchmark x86_64 backend crashes on boolean switch

3 participants