Skip to content

Force linking required globals#540

Merged
mshinwell merged 3 commits intoocaml:4.03from
trefis:force-linking-required-globals
Apr 18, 2016
Merged

Force linking required globals#540
mshinwell merged 3 commits intoocaml:4.03from
trefis:force-linking-required-globals

Conversation

@trefis
Copy link
Contributor

@trefis trefis commented Apr 13, 2016

While testing 4.03 at janestreet we noticed that sometimes the units linked in an executable were different depending on which compiler middle-end is used.

The first commit adds such an example to the test suite. The expected behavior, which is the one of 4.02 and 4.03 without flambda, is for Submodule to be linked in the executable and linked to be printed on stdout. With flambda, this doesn't happen.
From what I understand, the explanation is basically: flambda sees that the include is unused, drops it, and then since the unit/global Submodule is not mentioned anymore, it is not linked.

There is already some code in the compiler (in bytecomp/translmod.ml) to force some "required globals" to be linked, at the moment it works as follow:

for every "required global" (that set of globals is computed by the typechecker, and we will assume it is correct):

  • if it is already mentioned in the lambda code for the module, there is nothing to do; the unit will be linked
  • if it is not already mentioned, add a reference to it at the beginning of the lambda code; which forces the unit to be linked

As we saw in the example, with flambda it is not always enough anymore that the global be mentioned for the unit to be linked.
Similarly, simply adding a reference to it at the beginning will not suffice, flambda will notice it is unused and drop it.
What we want to do is to add, in all cases, a reference that flambda will not drop (we do this by using the opaque primitive).

@trefis trefis force-pushed the force-linking-required-globals branch from bebe92b to ff8f23f Compare April 13, 2016 17:38
@trefis trefis force-pushed the force-linking-required-globals branch from fe4950a to 015a967 Compare April 14, 2016 09:54
@mshinwell
Copy link
Contributor

I think this is OK.

@trefis
Copy link
Contributor Author

trefis commented Apr 14, 2016

Note about the implementation: I'm adding an flambda parameter to wrap_globals instead of simply using Config.flambda because with the later the behavior of the bytecode compiler is different depending on whether you enabled flambda at configure time or not, which seemed wrong.

@damiendoligez I'm considering this to be a bugfix and as such made the PR against 4.03. Does that make sense to you?

@damiendoligez damiendoligez added this to the 4.03.0 milestone Apr 18, 2016
@damiendoligez
Copy link
Member

@trefis Makes sense. Can we have a second review?

@lpw25
Copy link
Contributor

lpw25 commented Apr 18, 2016

I've reviewed it and think it is fine to merge.

@mshinwell mshinwell merged commit a455382 into ocaml:4.03 Apr 18, 2016
@trefis trefis deleted the force-linking-required-globals branch September 23, 2016 01:48
EduardoRFS pushed a commit to esy-ocaml/ocaml that referenced this pull request May 17, 2021
stedolan added a commit to stedolan/ocaml that referenced this pull request Mar 22, 2022
stedolan added a commit to stedolan/ocaml that referenced this pull request May 24, 2022
stedolan added a commit to stedolan/ocaml that referenced this pull request May 24, 2022
64235a3 flambda-backend: Change Float.nan from sNaN to qNaN (ocaml#466)
14a8e27 flambda-backend: Track GC work for all managed bigarray allocations (upstream 11022) (ocaml#569)
c3cda96 flambda-backend: Add two new methods to targetint for dwarf (ocaml#560)
e6f1fed flambda-backend: Handle arithmetic overflow in select_addr (ocaml#570)
dab7209 flambda-backend: Add Target_system to ocaml/utils (ocaml#542)
82d5044 flambda-backend: Enhance numbers.ml with more primitive types (ocaml#544)
216be99 flambda-backend: Fix flambda_o3 and flambda_oclassic attributes (ocaml#536)
4b56e07 flambda-backend: Test naked pointer root handling (ocaml#550)
40d69ce flambda-backend: Stop local function optimisation from moving code into function bodies; opaque_identity fixes for class compilation (ocaml#537)
f08ae58 flambda-backend: Implemented inlining history and use it inside inlining reports (ocaml#365)
ac496bf flambda-backend: Disable the local keyword in typing (ocaml#540)
7d46712 flambda-backend: Bugfix for Typedtree generation of arrow types (ocaml#539)
61a7b47 flambda-backend: Insert missing page table check in roots_nat.c (ocaml#541)
323bd36 flambda-backend: Compiler error when -disable-all-extensions and -extension are used (ocaml#534)
d8956b0 flambda-backend: Persistent environment and reproducibility (ocaml#533)
4a0c89f flambda-backend: Revert "Revert bswap PRs (480 and 482)" (ocaml#506)
7803705 flambda-backend: Cause a C warning when CAMLreturn is missing in C stubs. (ocaml#376)
6199db5 flambda-backend: Improve unboxing during cmm for Flambda (ocaml#295)
96b9e1b flambda-backend: Print diagnostics at runtime for Invalid (ocaml#530)
42ab88e flambda-backend: Disable bytecode compilers in ocamltest (ocaml#504)
58c72d5 flambda-backend: Backport ocaml#10595 from upstream/trunk (ocaml#471)
1010539 flambda-backend: Use C++ name mangling convention (ocaml#483)
81881bb flambda-backend: Local allocation test no longer relies on lifting (ocaml#525)
f5c4719 flambda-backend: Fix an assertion in Closure that breaks probes (ocaml#505)
c2cf2b2 flambda-backend: Add some missing command line arguments to ocamlnat (ocaml#499)

git-subtree-dir: ocaml
git-subtree-split: 64235a3
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Some of the books have multiple links, it would be nice to display them
all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants