···4646During this second execution, the test harness does whatever is physically
4747possible to allow these tests to proceed:
4848- Environment variables `CAML_LD_LIBRARY_PATH` and `OCAMLLIB` are manipulated to
4949- allow the compiler to operate
4949+ allow the compiler to operate (unless the compiler has been configured with
5050+ `--with-relative-libdir`)
5051- Bytecode executables which will no longer be able to find `ocamlrun` are
5152 explicitly passed to `ocamlrun`. The harness always verifies that this step is
5253 required by first executing the binary and ensuring that it fails and then
···7273- On Unix, the bytecode toplevel contains the absolute location of `ocamlrun`,
7374 so must be explicitly invoked via `ocamlrun`
7475- Both toplevels contain the absolute location of the Standard Library,
7575- requiring `OCAMLLIB` to be set
7676+ requiring `OCAMLLIB` to be set, unless the compiler was configured with
7777+ `--with-relative-libdir`
76787779### Loading archives/plugins (.cma / .cmxs) with `Dynlink`
7880···8486 compiler is available, then both `ocamlc` and `ocamlopt` will be native
8587 executables)
8688- Both compilers contain the absolute location of the Standard Library,
8787- requiring `OCAMLLIB` to be set
8989+ requiring `OCAMLLIB` to be set, unless the comnpiler was configured with
9090+ `--with-relative-libdir`
8891- The executable created by `ocamlc` contains the absolute location of
8992 `ocamlrun`, so must be both explicitly invoked via `ocamlrun` and also have
9093 `CAML_LD_LIBRARY_PATH` or `OCAMLLIB` adjusted, as that `ocamlrun` will not be
+1-1
testsuite/tools/cmdline.ml
···176176 "--pwd", Arg.Set_string pwd, "<pwd>\tCurrent working directory to use";
177177 "--bindir", Arg.String (check_exists ~absolute:true bindir), "\
178178<bindir>\tDirectory containing programs (must share a prefix with --libdir)";
179179- "--libdir", Arg.String (check_exists ~absolute:true libdir), "\
179179+ "--libdir", Arg.String (check_exists ~absolute:false libdir), "\
180180<libdir>\tDirectory containing stdlib.cma (must share a prefix with --bindir)";
181181 "--summary", Arg.Set summary, "";
182182 "--verbose", Arg.Set verbose, "";
···4444 if classification <> Vanilla then
4545 let fails =
4646 (* After the prefix has been renamed, bytecode executables compiled
4747- with -custom will still work. Otherwise, only executables where the
4848- header can search for ocamlrun and which do not require any C stubs
4949- to be loaded will still work. *)
4747+ with -custom will still work. Otherwise, the header needs to be
4848+ able to search for ocamlrun and, if applicable, ocamlrun needs to
4949+ be able to load C stubs (which will only happen if the runtime
5050+ locates the Standard Library using a relative directory, so that it
5151+ can find ld.conf) *)
5052 Environment.is_renamed env
5153 && match classification with
5254 | Tendered {dlls; _} ->
5353- not config.launcher_searches_for_ocamlrun || dlls
5555+ not config.launcher_searches_for_ocamlrun
5656+ || dlls && config.has_relative_libdir = None
5457 | _ ->
5558 false
5659 in
+16-7
testsuite/tools/testDynlink.ml
···6464 let runtime =
6565 mode = Bytecode && Harness.ocamlc_fails_after_rename config in
6666 (* In the Renamed phase, Config.standard_library will still point to the
6767- Original location *)
6868- let stdlib = true in
6767+ Original location, unless the compiler has been configured with a
6868+ relative libdir *)
6969+ let stdlib = (config.has_relative_libdir = None) in
6970 let (_, output) =
7071 Environment.run_process ~runtime ~stdlib env compiler args in
7172 Environment.display_output output
···8889 mode = Bytecode
8990 && expected_exit_code = None
9091 && not config.target_launcher_searches_for_ocamlrun
9292+ && config.has_relative_libdir = None
9193 in
9294 (* If the library needs C stubs to be loaded dynamically, then the runtime
9395 will need CAML_LD_LIBRARY_PATH set in the Renamed phase. *)
9496 let stubs =
9597 has_c_stubs
9698 && expected_exit_code = None
9999+ && Config.supports_shared_libraries
100100+ && config.has_relative_libdir = None
97101 in
98102 let expected_exit_code =
99103 match expected_exit_code with
···136140 let not_dynlink l = not (List.mem "dynlink" l) in
137141 let files, re_compile = compile_test_program () in
138142 let expected_exit_code =
139139- (* Bytecode executables launched using the executable header require
140140- caml_executable_name to know where the runtime is. As the Standard
141141- Library is only stored as an absolute path, this doesn't affect the
142142- execution of the test driver (yet). *)
143143- None in
143143+ (* Relocatable OCaml bytecode executables launched using the executable
144144+ header require caml_executable_name, or they end up being accidentally
145145+ relative, since the exec call leaves argv[0] as being the bytecode image
146146+ itself. *)
147147+ if mode = Bytecode && config.has_relative_libdir <> None
148148+ && Harness.no_caml_executable_name
149149+ && Environment.launched_via_stub test_program then
150150+ Some 2
151151+ else
152152+ None in
144153 let libraries = List.filter not_dynlink config.libraries in
145154 let () =
146155 List.iter (test_libraries_in_prog ?expected_exit_code env) libraries;
+33-16
testsuite/tools/testLinkModes.ml
···125125 around some problems with shared runtimes on s390x and riscv which don't
126126 reliably fail.
127127*)
128128-let run_program env _config =
128128+let run_program env config =
129129 let prefix = Environment.prefix env in
130130 let libdir_suffix = Environment.libdir_suffix env in
131131 let prefix, libdir_suffix =
···142142 if Environment.is_renamed env then
143143 stdlib_exists_when_renamed
144144 else
145145- false in
145145+ config.has_relative_libdir <> None in
146146 let args = [string_of_bool stdlib_exists; prefix; libdir_suffix] in
147147 let argv0 =
148148 if argv0 = test_program then
···259259 - Sys.argv.(0) doesn't equal Sys.argv.(3)
260260 - Config.standard_library exists when it shouldn't (or vice versa) *)
261261let test_runs usr_bin_sh test_program_path test_program
262262- _config env ~via_ocamlrun =
262262+ config env ~via_ocamlrun =
263263 let tests =
264264 let test_program_relative =
265265 Filename.concat Filename.current_dir_name test_program
···315315 else if Sys.win32 then
316316 (* stdlib/header.c correctly preserves argv[0] for Windows *)
317317 Success {executable_name = test_program_path; argv0}
318318+ else if Harness.no_caml_executable_name
319319+ && config.has_relative_libdir <> None then
320320+ (* Without caml_executable_name, ocamlrun will be forced to
321321+ interpret the relative standard library relative to argv[0],
322322+ which will fail. *)
323323+ Fail 134
318324 else
319325 (* stdlib/header.c does not preserve argv[0] for Unix *)
320326 Success {executable_name = argv0_resolved;
···351357 run in the Renamed phase for other reasons. *)
352358let make_test_runner ~stdlib_exists_when_renamed ~may_segfault ~with_unix
353359 ~tendered ~target_launcher_searches_for_ocamlrun usr_bin_sh
354354- test_program_path test_program config _env =
355355- (* Bytecode executables with absolute headers will need to be
356356- invoked via ocamlrun after the prefix has been renamed. *)
360360+ test_program_path test_program config env =
361361+ (* Bytecode executables with absolute headers will need to be invoked via
362362+ ocamlrun after the prefix has been renamed. *)
357363 let via_ocamlrun =
358364 tendered && not target_launcher_searches_for_ocamlrun
365365+ && (config.has_relative_libdir = None || not (Environment.is_renamed env))
359366 in
360367 let rec run env =
361368 let runs =
···367374 | Fail code -> "", code, ""
368375 | Success {executable_name; argv0} -> executable_name, 0, argv0
369376 in
370370- let stubs = tendered && with_unix in
377377+ let stubs = tendered && with_unix && config.has_relative_libdir = None in
371378 run_program
372379 env config ~runtime:via_ocamlrun ~stubs
373380 test_program_path ~prefix_path_with_cwd expected_executable_name
···563570 options
564571 in
565572 let options =
566566- if Environment.is_renamed env then
573573+ if Environment.is_renamed env || config.has_relative_libdir <> None then
567574 options
568575 else
569576 let new_libdir =
···604611 let runtime =
605612 mode = Bytecode && Harness.ocamlc_fails_after_rename config in
606613 (* In the Renamed phase, Config.standard_library will still point to
607607- the Original location *)
608608- let stdlib = true in
614614+ the Original location, unless the compiler has been configured
615615+ with a relative libdir *)
616616+ let stdlib = (config.has_relative_libdir = None) in
609617 Environment.run_process ~fails ~runtime ~stdlib env compiler args
610618 in
611619 Environment.display_output output;
···633641 `None
634642 else
635643 let stdlib_exists_when_renamed =
636636- (* In the Original phase, -set-runtime-default is used to set
637637- standard_library_default to the Renamed phase's location. When
638638- the tests are recompiled in the Renamed phase, this is not done.
639639- The effect is that if any test is being run in the Renamed phase,
640640- Config.standard_library will be correct. *)
641641- not (Environment.is_renamed env)
644644+ if config.has_relative_libdir = None then
645645+ (* In the Original phase, for a compiler with an absolute libdir,
646646+ -set-runtime-default is used to set standard_library_default to
647647+ the Renamed phase's location. When the tests are recompiled in
648648+ the Renamed phase, this is not done. The effect is that if any
649649+ test is being run in the Renamed phase, Config.standard_library
650650+ will be correct. *)
651651+ not (Environment.is_renamed env)
652652+ else
653653+ (* When the compiler has a relative libdir, -set-runtime-default
654654+ is implicitly being tested by the build process, and we wish to
655655+ test the opposite in the harness - thus the test programs
656656+ compiled in the Original phase will _not_ be able to find the
657657+ Standard Library in the Renamed phase. *)
658658+ Environment.is_renamed env
642659 in
643660 make_test_runner ~stdlib_exists_when_renamed ~may_segfault ~with_unix
644661 ~tendered ~target_launcher_searches_for_ocamlrun
+32-12
testsuite/tools/testRelocation.ml
···5959 (* Determine if the installation prefix should be found in this file *)
6060 let prefix =
6161 let code_embeds_stdlib_location =
6262- (* The runtime binaries all contain OCAML_STDLIB_DIR and everything
6363- except flexlink and ocamllex link with the Config module, either
6464- directly or via ocamlcommon *)
6565- not (List.mem basename ["flexlink.byte"; "flexlink.opt"; "flexlink";
6666- "ocamllex.byte"; "ocamllex.opt"; "ocamllex";
6767- "ocamlyacc"])
6262+ (* If the compiler is configured with an absolute libdir, the runtime
6363+ binaries all contain OCAML_STDLIB_DIR and everything except flexlink
6464+ and ocamllex link with the Config module, either directly or via
6565+ ocamlcommon *)
6666+ config.has_relative_libdir = None
6767+ && not (List.mem basename ["flexlink.byte"; "flexlink.opt"; "flexlink";
6868+ "ocamllex.byte"; "ocamllex.opt"; "ocamllex";
6969+ "ocamlyacc"])
6870 in
6971 let linker_embeds_stdlib_location =
7072 (* If the launcher doesn't search for ocamlrun, then either the #! stub
···160162 ~ocaml_debug:has_ocaml_debug_info,
161163 ~c_debug:has_c_debug_info,
162164 ~s:contains_assembled_objects) =
163163- if basename = "Makefile.config" || basename = "runtime-launch-info" then
164164- (* These files all embed the Standard Library location *)
165165+ if basename = "Makefile.config" then
166166+ (* Embeds the Standard Library location *)
165167 (~stdlib:true, ~ocaml_debug:false, ~c_debug:false, ~s:false)
166168 else if basename = "config.cmx" then
167169 (* config.cmx contains Config.standard_library for inlining *)
168168- (~stdlib:true, ~ocaml_debug:false, ~c_debug:false, ~s:false)
170170+ let stdlib =
171171+ config.has_relative_libdir = None && not Config.flambda in
172172+ (~stdlib, ~ocaml_debug:false, ~c_debug:false, ~s:false)
169173 else if List.mem ext [".cma"; ".cmo"; ".cmt"; ".cmti"] then
170174 let stdlib = (* via Config.standard_library *)
171171- List.mem basename ["config.cmt"; "config_main.cmt";
172172- "ocamlcommon.cma"] in
175175+ config.has_relative_libdir = None
176176+ && List.mem basename ["config.cmt"; "config_main.cmt";
177177+ "ocamlcommon.cma"] in
178178+ (* The compiler's artefacts are all compiled with -g *)
173179 (~stdlib, ~ocaml_debug:true, ~c_debug:false, ~s:false)
180180+ else if basename = "runtime-launch-info" then
181181+ (* When the compiler is configured with a relative libdir,
182182+ runtime-launch-info just contains ".", rather than the prefix *)
183183+ let stdlib = (config.has_relative_libdir = None) in
184184+ (~stdlib, ~ocaml_debug:false, ~c_debug:false, ~s:false)
174185 else if ext = ".cmxs" then
175186 (* All the .cmxs files built by the distribution at present include C
176187 objects and obviously contain assembled objects. *)
···191202 Sys.file_exists (Filename.remove_extension file ^ ".cmxa") in
192203 (* Config.standard_library is in ocamlcommon and the bytecode runtime
193204 embeds the Standard Library location *)
194194- let stdlib = Filename.remove_extension basename = "ocamlcommon" in
205205+ let stdlib =
206206+ config.has_relative_libdir = None
207207+ && Filename.remove_extension basename = "ocamlcommon" in
195208 (~stdlib, ~ocaml_debug:false, ~c_debug:(not is_ocaml), ~s:is_ocaml)
196209 else
197210 (* DLLs are either the shared versions of the runtime libraries or
···225238 LocationSet.singleton Prefix
226239 else
227240 LocationSet.empty
241241+ in
242242+ let prefix =
243243+ if config.has_relative_libdir <> None
244244+ && basename = "Makefile.config" then
245245+ LocationSet.add Relative prefix
246246+ else
247247+ prefix
228248 in
229249 if contains_build_path then
230250 LocationSet.add Build prefix
+1-1
testsuite/tools/testToplevel.ml
···9797 Environment.run_process
9898 ~fails:(expected_exit_code <> 0)
9999 ~runtime:(mode = Bytecode && not config.launcher_searches_for_ocamlrun)
100100- ~stdlib:true env toplevel args
100100+ ~stdlib:(config.has_relative_libdir = None) env toplevel args
101101 in
102102 Environment.display_output output;
103103 if exit_code <> expected_exit_code then
+7-5
testsuite/tools/test_in_prefix.ml
···144144145145 For the compiler's files to be reproducible, the compiler needs to be both
146146 relocatable and also required support from the assembler and C compiler. *)
147147- let relocatable = false in
147147+ let relocatable =
148148+ config.has_relative_libdir <> None
149149+ && config.launcher_searches_for_ocamlrun
150150+ in
148151 let reproducible =
149149- relocatable
152152+ relocatable && false
150153 (* At present, the compiler build doesn't actually take advantage of this
151151- configuration, but this does not matter because the compiler cannot yet
152152- be relocatable! *)
154154+ configuration *)
153155 && (not config.has_ocamlopt
154156 || not Toolchain.assembler_embeds_build_path
155157 || Config.as_has_debug_prefix_map && Config.architecture <> "riscv")
···157159 && (not Toolchain.c_compiler_always_embeds_build_path
158160 || not Toolchain.c_compiler_debug_paths_can_be_absolute)
159161 in
160160- let target_relocatable = false in
162162+ let target_relocatable = config.target_launcher_searches_for_ocamlrun in
161163 (* Use Harness.pp_path unless --verbose was specified *)
162164 let pp_path =
163165 if verbose then
+19-7
testsuite/tools/test_ld_conf.ml
···3939and var_setting = Unset | Empty | Set of string list
40404141(* Set of tests to run in a given environment *)
4242-let tests _config env =
4242+let tests config env =
4343 (* Convenience function - [if_ld_conf_found outcome] returns the empty list in
4444 the Renamed phase. *)
4545 let if_ld_conf_found outcome =
4646- (* ocamlrun can't find ld.conf after the prefix has been renamed *)
4747- if Environment.is_renamed env then
4646+ (* ocamlrun can only find ld.conf after the prefix has been renamed if it's
4747+ configured with --with-relative-libdir *)
4848+ if Environment.is_renamed env && config.has_relative_libdir = None then
4849 []
4950 else
5051 outcome
···6364 Environment.libdir env
6465 else
6566 Config.standard_library in
6767+ let libdir =
6868+ if config.has_relative_libdir = None then
6969+ libdir
7070+ else
7171+ (* Unix.realpath raises Invalid_argument if it's not available *)
7272+ try Unix.realpath libdir
7373+ with Invalid_argument _ -> libdir in
6674 let (/) = Filename.concat in
6775 let data = [
6876 (* Root directory (both forms) preserved *)
···326334 let runtime =
327335 mode = Bytecode && Harness.ocamlc_fails_after_rename config in
328336 (* In the Renamed phase, Config.standard_library will still point to the
329329- Original location *)
330330- let stdlib = true in
337337+ Original location, unless the compiler has been configured with a
338338+ relative libdir *)
339339+ let stdlib = (config.has_relative_libdir = None) in
331340 let (_, output) =
332341 Environment.run_process ~runtime ~stdlib env compiler args in
333342 Environment.display_output output;
···342351 in
343352 (* In the Renamed phase, the test driver will need to be launched with
344353 ocamlrun, unless executables produced by the compiler are capable of
345345- searching for the runtime (as the Windows executable launcher does) *)
354354+ searching for the runtime (as the Windows executable launcher does) or
355355+ the compiler has been configured with a relative libdir (as in this mode
356356+ the bytecode header will have the correct location) *)
346357 let runtime =
347358 mode = Bytecode
348348- && not config.target_launcher_searches_for_ocamlrun in
359359+ && not config.target_launcher_searches_for_ocamlrun
360360+ && config.has_relative_libdir = None in
349361 let run run_process test =
350362 let code, lines =
351363 run_process ~runtime test_program []