Closed Bug 1457295 Opened 6 years ago Closed 6 years ago

lld does not correctly order NSModules

Categories

(Firefox Build System :: General, enhancement)

3 Branch
enhancement
Not set
normal

Tracking

(firefox62 fixed)

RESOLVED FIXED
mozilla62
Tracking Status
firefox62 --- fixed

People

(Reporter: tjr, Assigned: tjr)

References

Details

Attachments

(1 file)

We require NSModules to be ordered correctly:
https://searchfox.org/mozilla-central/rev/78dbe34925f04975f16cb9a5d4938be714d41897/toolkit/library/libxul.mk#24

lld does not order them correctly, even when the .list of objects is ordered correctly.

Options:

a) There may be something possible with a hack like https://searchfox.org/mozilla-central/rev/78dbe34925f04975f16cb9a5d4938be714d41897/toolkit/library/StaticXULComponentsEnd/StaticXULComponentsEnd.cpp#6 and using --sort-section=name but experimenting with --sort-section=name didn't seem to produce expected output. Nothing was sorted by anything I could understand (sample: https://pastebin.mozilla.org/9084004).



b) I _can_ pass -Wl,--symbol-ordering-file <file> where <file> is a sorted list of symbols. This does work. The ugly part is I have to generate that file, probably with something like 
> sed '...' libxul.so.list' | nm -g | grep NSModule | grep -v (Start|End) | sort 



c) (Ted's idea) We can do away with this whole .kPStaticModules hack entirely. The whole point of this is to build up an array of modules: https://searchfox.org/mozilla-central/rev/78dbe34925f04975f16cb9a5d4938be714d41897/xpcom/components/nsComponentManager.cpp#260

If we instead added something like the following to moz.build files:

> XPCOM_STATIC_MODULES += ['<module_variable_name>']

we could generate a source file and make the array that way.  

We can add something in the build system that adds a special define so that NSMODULE_DEFN won't compile without it to avoid someone omitting a XPCOM_STATIC_MODULES line.
Flags: needinfo?(mh+mozilla)
Heh I forgot about Option 4: Just reuse the MSVC hack, which (which when appropriatly converted for clang) orders things correctly: https://pastebin.mozilla.org/9084017

I'm going to attach that to this bug once I clean it up tomorrow.
Comment on attachment 8971579 [details]
Bug 1457295 Trick clang+lld+lto into ordering NSModules correctly also

https://reviewboard.mozilla.org/r/240356/#review246614

::: toolkit/library/StaticXULComponentsEnd/StaticXULComponentsEnd.cpp:12
(Diff revision 2)
>   * sections with the same first part are all grouped, and ordered
>   * alphabetically with the second part as sort key. */
>  #  pragma section(".kPStaticModules$Z", read)
>  #  undef NSMODULE_SECTION
>  #  define NSMODULE_SECTION __declspec(allocate(".kPStaticModules$Z"), dllexport)
> +#elif defined(XP_LINUX) && MOZ_LTO

There is no reason to make this linux-only.
Attachment #8971579 - Flags: review?(mh+mozilla)
Flags: needinfo?(mh+mozilla)
assigning to tjr since he attached patches
Assignee: nobody → tom
Comment on attachment 8971579 [details]
Bug 1457295 Trick clang+lld+lto into ordering NSModules correctly also

https://reviewboard.mozilla.org/r/240356/#review246842

::: toolkit/library/StaticXULComponentsEnd/StaticXULComponentsEnd.cpp:13
(Diff revision 3)
> +/* Clang+lld with LTO does not order modules correctly either, but fortunately
> + * the same trick works. */

I remembered about the hack in toolkit/library/StaticXULComponentsEnd/moz.build. Is StaticXULComponentsEnd built with -fno-lto when that happens?
Attachment #8971579 - Flags: review?(mh+mozilla)
Comment on attachment 8971579 [details]
Bug 1457295 Trick clang+lld+lto into ordering NSModules correctly also

https://reviewboard.mozilla.org/r/240356/#review250272

::: toolkit/library/StaticXULComponentsEnd/StaticXULComponentsEnd.cpp:13
(Diff revision 3)
> +/* Clang+lld with LTO does not order modules correctly either, but fortunately
> + * the same trick works. */

Yes; even when we compile StaticXULComponentsEnd with -fno-lto stuff doesn't get ordered correctly.
Flags: needinfo?(mh+mozilla)
Flags: needinfo?(mh+mozilla)
Comment on attachment 8971579 [details]
Bug 1457295 Trick clang+lld+lto into ordering NSModules correctly also

https://reviewboard.mozilla.org/r/240356/#review250520
Attachment #8971579 - Flags: review+
Pushed by cbrindusan@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/813d8cffc9c9
Trick clang+lld+lto into ordering NSModules correctly also r=glandium
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/813d8cffc9c9
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
Version: Version 3 → 3 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: