Closed Bug 1077384 Opened 10 years ago Closed 10 years ago

Make libmozglue a pseudo-LD_PRELOAD on android

Categories

(Core :: mozglue, defect)

All
Android
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla35

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(1 file, 3 obsolete files)

      No description provided.
In order to avoid adding more dlsym overhead than there already is, resolve
symbols directly in the library containing the linker. (GetSymbolPtr is
essentially free ; dlsym makes the system linker compule a ElfHash itself,
and that's quite expensive to do on all symbols)

This also paves the way for direct symbol resolution in all system libraries.

In terms of code layout, I want BaseElf to merge with LibHandle eventually,
once SystemElf switches over, which explains why I moved code around in a
separate file.
Attachment #8499528 - Flags: review?(nfroyd)
Blocks: 1077148
(In reply to Mike Hommey [:glandium] from comment #2)
> https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=efbd75e19459

So, this is interesting... this is all orange, but the build works on my phone...
(In reply to Mike Hommey [:glandium] from comment #3)
> (In reply to Mike Hommey [:glandium] from comment #2)
> > https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=efbd75e19459
> 
> So, this is interesting... this is all orange, but the build works on my
> phone...

This may well have been my ANDROID_PACKAGE_NAME trick that it didn't like. Trying again without:
https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=50d8b90140ce
Blocks: 1077366
https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=52ad66234009
Turns out all the orange was... lack of reentrancy in dl* functions on Android < 4.1.
Attachment #8499904 - Flags: review?(nfroyd)
Attachment #8499528 - Attachment is obsolete: true
Attachment #8499528 - Flags: review?(nfroyd)
Huh, with a return type for Init, it should be better
https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=8bbb4a29d456
Attachment #8499942 - Flags: review?(nfroyd)
Attachment #8499904 - Attachment is obsolete: true
Attachment #8499904 - Flags: review?(nfroyd)
Sigh, still missing return type, in the implementation this time. I *will* get this right dammit.
https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=1929ef22cf2d
Attachment #8499946 - Flags: review?(nfroyd)
Attachment #8499942 - Attachment is obsolete: true
Attachment #8499942 - Flags: review?(nfroyd)
Comment on attachment 8499946 [details] [diff] [review]
Make libmozglue a pseudo-LD_PRELOAD on android

Review of attachment 8499946 [details] [diff] [review]:
-----------------------------------------------------------------

::: mozglue/linker/CustomElf.cpp
@@ +362,5 @@
>    for (std::vector<RefPtr<LibHandle> >::const_iterator it = dependencies.begin();
>         it < dependencies.end(); ++it) {
>      if (!(*it)->IsSystemElf()) {
> +      sym = static_cast<BaseElf *>(
> +        reinterpret_cast<CustomElf *>((*it).get()))->GetSymbolPtr(symbol, hash);

The static_cast here isn't necessary, is it?  I don't see a GetSymbolPtr override in CustomElf.  Also, I think this reinterpret_cast can be static_cast.

Also, more of a code cleanliness idea than anything: this IsSystemElf/reinterpret_cast stuff seems to happen fairly often, you could just consider:

  if (CustomElf* ce = (*it)->AsCustomElf()) {
    ...
  }

or similar.
Attachment #8499946 - Flags: review?(nfroyd) → review+
(In reply to Nathan Froyd (:froydnj) from comment #8)
> Comment on attachment 8499946 [details] [diff] [review]
> Make libmozglue a pseudo-LD_PRELOAD on android
> 
> Review of attachment 8499946 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: mozglue/linker/CustomElf.cpp
> @@ +362,5 @@
> >    for (std::vector<RefPtr<LibHandle> >::const_iterator it = dependencies.begin();
> >         it < dependencies.end(); ++it) {
> >      if (!(*it)->IsSystemElf()) {
> > +      sym = static_cast<BaseElf *>(
> > +        reinterpret_cast<CustomElf *>((*it).get()))->GetSymbolPtr(symbol, hash);
> 
> The static_cast here isn't necessary, is it?  I don't see a GetSymbolPtr
> override in CustomElf.

There is CustomElf::GetSymbolPtr(const char *symbol), and that makes the static_cast necessary.

> Also, I think this reinterpret_cast can be
> static_cast.
> 
> Also, more of a code cleanliness idea than anything: this
> IsSystemElf/reinterpret_cast stuff seems to happen fairly often, you could
> just consider:
> 
>   if (CustomElf* ce = (*it)->AsCustomElf()) {
>     ...
>   }
> 
> or similar.

Will file a followup.
https://hg.mozilla.org/mozilla-central/rev/7c1604224596
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla35
Blocks: 1081034
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: