Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Merge ReadyToRun header pointers on Unix platforms - #1089

Merged
nattress merged 1 commit into
dotnet:masterfrom
nattress:linkscript
Apr 8, 2016
Merged

nattress merged 1 commit into
dotnet:masterfrom
nattress:linkscript

Conversation

@nattress

@nattress nattress commented Apr 6, 2016

Copy link
Copy Markdown
Contributor

Add a linker script which controls how sections are merged to group
together module header indirection cells. This allows the ReadyToRun
headers to be collated and iterated at start up. The updated CLI looks
for a file named "linkerscript" in the CoreRT SDK folder and passes it
to the linker on Unix platforms if so.

Remove work-around for Unix from ModulesSectionNode that was inserting
symbols for __modules_a and __modules_z which are now consumed from
those defined in main.cpp and linked in from libbootstrapper.a

Comment thread src/Native/Bootstrap/main.cpp Outdated
__attribute((section (".modules$A"))) void * __modules_a[] = { nullptr };
__attribute((section (".modules$Z"))) void * __modules_z[] = { nullptr };

extern "C" void * __modules_a[];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this still needed?

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.

Not sure yet - I should have tagged this as WIP since I need to get OSX working before this is done. Jan moved this code into bootstrap which should be the only place it's used so we may no longer need the externs.

@nattress nattress changed the title Merge ReadyToRun header pointers on Unix platforms [WIP] Merge ReadyToRun header pointers on Unix platforms Apr 7, 2016
@nattress nattress changed the title [WIP] Merge ReadyToRun header pointers on Unix platforms Merge ReadyToRun header pointers on Unix platforms Apr 8, 2016
@nattress

nattress commented Apr 8, 2016

Copy link
Copy Markdown
Contributor Author

@MichalStrehovsky Ok this is now complete - PTAL :) I need dotnet/llilc#1049 to go through first so this will work on the CI box, though.

Comment thread src/Native/Bootstrap/main.cpp Outdated
// data pointer into RegisterReadyToRunModule where we save it in a list for the startup
// code to consume.
//
std::vector<void*> __registeredModules;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to not introduce dependency on C++ STL - it pulls in a pile of stuff that we do not have/need.

@jkotas

jkotas commented Apr 8, 2016

Copy link
Copy Markdown
Member

Just a thought - would it make things simple if we used the same scheme on Linux as what you have built for OSX?

@jkotas

jkotas commented Apr 8, 2016

Copy link
Copy Markdown
Member

LGTM

@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The file naming convention seem to be "X64NodeType" so this would be X64SingleArgumentJumpThunk.cs". I don't necessarily agree with the convention, but let's be consistent.

@MichalStrehovsky

Copy link
Copy Markdown
Member

LGTM otherwise.

@nattress

nattress commented Apr 8, 2016

Copy link
Copy Markdown
Contributor Author

Looking at the ELF spec, it looks like there's a MachO equivalent for a section with an array of init pointers: ELF::SHT_INIT_ARRAY. I'll look into this for a follow up check-in.

Linux
Add a linker script which controls how sections are merged to group together module header indirection cells. This allows the ReadyToRun headers to be collated and iterated at start up. The updated CLI looks for a file named "linkerscript" in the CoreRT SDK folder and passes it to the linker on Unix platforms if so.

Remove work-around for Unix from ModulesSectionNode that was inserting symbols for __modules_a and __modules_z which are now consumed from those defined in main.cpp and linked in from libbootstrapper.a

OSX
On Windows / Linux each compiled object file contains a section, .Modules$I, which has a pointer to the ReadyToRun header describing the module's global data. The linker on those platforms collects all object file .Modules$I sections and sandwiches them between two other sections:.Modules$A and .Modules$Z in which we store sentinel symbols available at runtime to iterate the list of ReadyToRun headers.

On OSX the linker doesn't support this model. Instead, a MachO section with the type S_MOD_INIT_FUNC_POINTERS can be created. In that section, place a function pointer. At binary load time, the OS loader will scan for these sections and call all functions in them. Introduce a jump thunk in the compiler that carries the ReadyToRun header address in it. At runtime, it calls a native helper which collects all headers and passes them to the regular startup code.
@nattress
nattress merged commit b570b7e into dotnet:master Apr 8, 2016
@nattress
nattress deleted the linkscript branch April 8, 2016 23:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants