Skip to content

Comments

Switch Android onto the sectionELF style of module registry, but leave out the unused register_dso and friends#2172

Merged
joakim-noah merged 1 commit intomasterfrom
android
Jun 25, 2017
Merged

Switch Android onto the sectionELF style of module registry, but leave out the unused register_dso and friends#2172
joakim-noah merged 1 commit intomasterfrom
android

Conversation

@joakim-noah
Copy link
Contributor

@joakim-noah joakim-noah commented Jun 18, 2017

dmd moved from the linked list at _Dmodule_ref to a bracketed section a couple years ago, so I've been reverting that druntime commit for ldc/Android till now. Turns out I can use this sectionELF code just fine, as long as I take out the calls to _d_dso_registry and modify druntime to use the slightly different ldc symbols __start___minfo and __stop___minfo, druntime PR forthcoming. Confirmed by cross-compiling the stdlib tests from linux/x64 to Android/ARM with ldc master, and running the stdlib and dmd testsuite natively with master and merge-2.074.

I didn't look very closely at sectionELF however, just hacked this in, so if David thinks anything else might cause issues, let me know.

gen/modules.cpp Outdated
LLValue *params[] = {b.getFalse(), minfoRefPtr};
b.CreateCall(registerDSO, params);
if (global.params.targetTriple->getEnvironment() != llvm::Triple::Android)
b.CreateCall(registerDSO, params);
Copy link
Member

Choose a reason for hiding this comment

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

Why would any of the code be needed in the executable? This still emits the registerDSO functions and ctors/dtors that do nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about removing the call to buildRegisterDSO also, but figured I'd keep this patch minimal. As for the ctor/dtor, I initially simply switched away from the linked list of module info and built it, saw the linker complain that it couldn't find _d_dso_registry, then took out the two calls that added it. It took a couple minutes, as I wasn't about to dive into all the complexity of everything else you do here.

If you think I should just remove this entire last block instead on Android, I can do that.

Copy link
Member

Choose a reason for hiding this comment

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

What I'm asking for is to just not call any of the stuff that actually generates executable code. This should amount to always taking the !isFirst early return above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't seem like that'll work as I need the __start___minfo/__stop___minfo symbols in druntime, as mentioned above. I'll investigate.

Copy link
Member

Choose a reason for hiding this comment

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

__start_minfo/__stop_minfo are generated by the linker. The code here merely uses them (to achieve something along the lines of what you are doing in druntime).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, if you say so. :) I don't want to try and understand everything you did here, hence simply reverting that druntime commit on Android for so long.

I just tried exiting early in emitModuleRefToSection where you indicated and the druntime test runner builds and all modules pass, same with a small sample file. I'll try the phobos test runner and dmd testsuite next and update this PR in the way you suggested once everything passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passes all the tests when done the way you wanted, so updated the PR.

@dnadlinger
Copy link
Member

Be aware that this might break --gc-sections (if it ever worked on Android).

@joakim-noah
Copy link
Contributor Author

--gc-sections always worked fine before and after this patch, but I make sure the ld.bfd linker is being used, because gold would reorder the TLS sections and I don't know of an easy way to make it keep those sections together, as the default ld.bfd linker script does. If the issue is mostly with gold, that doesn't matter to me right now.

@dnadlinger
Copy link
Member

--gc-sections always worked fine before and after this patch

How do you avoid the module info references being garbage collected?

@joakim-noah
Copy link
Contributor Author

I'm unclear exactly how --gc-sections works, I'm just reporting what happens, ie the module info is always there, as the test runner uses it to run the unit tests. I now see that the __minfo section is currently left in the final executable, while the register_dso section is generated for an object file compiled from a small D source file but not in the final executable, presumably removed by the linker.

I've not looked into why it keeps some sections and throws out others, let me know if you want me to investigate, if there's something I should look for. I had the impression gold was much more aggressive at removing sections than ld.bfd, maybe that explains it.

@joakim-noah joakim-noah changed the title Switch Android onto the sectionELF style of module registry, but remove the unused _d_dso_registry calls Switch Android onto the sectionELF style of module registry, but leave out register_dso and friends Jun 21, 2017
@joakim-noah joakim-noah changed the title Switch Android onto the sectionELF style of module registry, but leave out register_dso and friends Switch Android onto the sectionELF style of module registry, but leave out the unused register_dso and friends Jun 21, 2017
@joakim-noah
Copy link
Contributor Author

joakim-noah commented Jun 24, 2017

Submitted the druntime fixes upstream, dlang/druntime#1851, would be nice to get these two pulls in before the final 1.3 release, so I can reduce the patches needed for my ldc Termux package for Android.

Anything else holding this pull up, David?

@dnadlinger
Copy link
Member

Should be fine - feel free to merge if "green". An explanation in the code would be good, though - the rest of the module registry code is fairly well documented (although it should probably be split up into multiple functions).

…g upstream, but leave out the dso_registry stuff that's unused on Android.
@joakim-noah
Copy link
Contributor Author

Thanks for the review, added comment and merged. If you approve the upstream druntime pull linked above, I'll go ahead and merge it in the ldc branch.

@JohanEngelen JohanEngelen deleted the android branch June 25, 2017 07:30
@JohanEngelen JohanEngelen mentioned this pull request Jun 25, 2017
6 tasks
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