-
Notifications
You must be signed in to change notification settings - Fork 510
Conversation
Will take some time to investigate |
It's possible something else fails. I fell for the trap of thinking that different exit codes mean different failures in the test, but the SharedLibrary test exits with 1 for all failures. |
I've tried it in my project and got error from dlopen(): undefined symbol: g_compilerEmbeddedSettingsBlob |
I've creatred simple stub in C with just this exported variable:
Then added this stub to linking and got working .so library, which was sucsessfully loaded. |
Why this struct? May the nature of that symbol is CompilerEmbeddedSettingsBlob defined at https://github.com/dotnet/corert/blob/master/src/Native/Runtime/RhConfig.cpp |
I've just took it from generated cpp files (like tests\src\Simple\Delegates\obj\Release\x64\native\Delegates.cpp) |
On master I also get SIGABRT.
|
@@ -859,7 +859,7 @@ public void EmitSymbolDefinition(int currentOffset) | |||
AppendExternCPrefix(_sb); | |||
name.AppendMangledName(_nodeFactory.NameMangler, _sb); | |||
|
|||
EmitSymbolDef(_sb); | |||
EmitSymbolDef(_sb, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least g_compilerEmbeddedSettingsBlob BlobNode must be global
After making BlobNode Global I can compile valid .so without stub. But now I geting SegFault in switch:
|
If I had to venture a guess, it's a problem with how RyuJIT-generated code refers to the jump table data. We're probably not doing the right reloc for it with this change. I would look at how the reloc referenced from there looks like in assembly and what it's pointing at. |
Maybe disassemble of ComputeHash32, which faults will help:
SigFault caused by |
Maybe I'm wrong, but it looks like |
@@ -391,10 +396,12 @@ int ObjectWriter::EmitSymbolRef(const char *SymbolName, | |||
case RelocType::IMAGE_REL_BASED_REL32: | |||
Size = 4; | |||
IsPCRel = true; | |||
Kind = MCSymbolRefExpr::VK_PLT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VK_PLT is for code symbols, and for data symbols it should be VK_GOTPCREL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking into this! You probably know more about ELF relocs than me at this point.
Is there any way to express "this reloc points to something that is part of the ELF module and will for sure fit in the 32 bit reloc" because it's in the same file?
Part of the reason why I marked this pull request WIP is because I don't particularly like we have to go through jump stubs to access symbols that are defined within the same module (some of these relocs literally point to things that are in the same .o
file, the others point to things that are in libRuntime.so). GOTPCREL will similarly require an indirection to access things that are right there.
If this is something that we have to live with, we can probably introduce a --pic
command line option for ILC and have it generate the necessary indirections under that switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just studied all this relocation tricks for ELF :)
But, as I understand - this indirections is a standard way of making shared libs in *nix.
There is question on StackOverflow about that:
here https://stackoverflow.com/questions/53086636/linking-a-static-library-into-a-shared-library-without-fpic
and here https://stackoverflow.com/questions/51417700/relocation-errors-when-linking-a-static-library-with-shared-library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe symbol type R_X86_64_PC32 means "32 bit offset relative to procedure call".
But LD will allow this type only for local symbols.
I've tried to make all symbols LOCAL, except ExternSymbolNode. Everything get linked, but still have a problem with stack unwinding. It can't find FDE in getInfoFromDwarfSection()
Yes, making symbols to be local is the way to go. The equivalent C/C++ construct is We may need to have a flag on |
Hm. I've found 2 code branches, which searches for UnwindSection by PC. And it looks like second one (which is used in GC) has searched wrong UnwindSection. |
It's funny, but function UnwindHelpers.LocateSectionsCallback just didn't check result :)
Fixed it and got working lib, Hurray! |
@hc4 Thank you for looking into this. This is great work. Do you plan to PR the fixes you have made? |
I still have SIGFAULT in RhpUniversalTransition_DebugStepTailCall when library loaded with RTLD_LAZY option. |
I've got it working with help of hack at
replaced with
to avoid PLT relocationat at runtime Now it works in RTLD_LAZY mode |
Should I create new PR into coret/master or just my fixes into MichalStrehovsky:exper? |
Please make a new one - I'll just close this one then. |
Closing in favor of #7249. |
Progress towards #4988.
The relocation issues we're having are due to two things: we emit all symbols as global, and we don't do the dance that is necessary to access symbols someone else could redefine in a different module and make them "too far away" to fit in a 32bit relocation. Ideally, we should find a way to ban this because I think it's breaking our ability to have static libraries built by different versions of CoreRT in the same process (they're going to redefine each other's symbols and that sounds bad).
I ran out of time I allocated for myself for this. This is enough to actually build SharedLibrary.so, but the test is failing (because dlopen fails for reasons that I didn't investigate) and I didn't validate this doesn't break Windows or other (non-dynamic library) scenarios.
I'll need to read up more on ELF relocs at some point.
Putting it up in case someone would like to pick this up. I don't know when I'll be able to make time for this again.
Cc @tonerdo @tim241 @sebastianulm