Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid .text.startup #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Avoid .text.startup #2

wants to merge 2 commits into from

Conversation

melonedo
Copy link

@melonedo melonedo commented Oct 4, 2022

@melonedo melonedo changed the title Avoid .text.startup [WIP] Avoid .text.startup Oct 5, 2022
@melonedo melonedo changed the title [WIP] Avoid .text.startup Avoid .text.startup Oct 5, 2022
@Gnimuc
Copy link
Owner

Gnimuc commented Oct 5, 2022

Could you elaborate a bit more about how .text.startup triggers the assertion? To me, it seems that somehow Julia fails to correctly call finalizeMemory. (EDIT: it turns out these methods are interfaces of LLVM's memory manager and Julia just implements a customized version to workaround some multi-threading issues related to libunwind)

@melonedo
Copy link
Author

melonedo commented Oct 5, 2022

If you check what sections are generated by inspecting ELFWriter::writeObject, you will find that two text sections (.text and .text.startup) are emitted. The reason behind .text.startup is that constructors are grouped in a separate section to improve space locality.

Note: you will need to trace MCAsmBackend::createObjectWriter on other platforms to determine the writer.

@Gnimuc
Copy link
Owner

Gnimuc commented Oct 5, 2022

Thanks for the link. That explains why/how the .text.startup section is emitted. But I still can't find any clue on why Julia uses code_allocated and forces a single code section when implementing the memory manager.

@Gnimuc
Copy link
Owner

Gnimuc commented Oct 5, 2022

I think I found the reason. Just several lines above that line, there is a comment:

// allocating more than one code section can confuse libunwind.

Comment on lines +1469 to +1474
for (auto &GF : jl_Module) {
if (GF.getSection() == ".text.startup") {
GF.setSection("");
}
}

Copy link
Owner

Choose a reason for hiding this comment

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

There is probably another way to fix the libunwind issue. But if we compromise on Julia's implementation, do we need to ignore other sections? like:

  for (auto &GF : jl_Module) {
     if (GF.getSection() != ".text") {
       GF.setSection("");
     }
   }

Copy link
Author

Choose a reason for hiding this comment

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

That is a valid choice, I just want to be conservative here. I think we can delay this until more tests are passed.

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.

2 participants