diff --git a/dirs-and-confs.txt b/dirs-and-confs.txt index 3cb4d38fec..1d77ebb707 100644 --- a/dirs-and-confs.txt +++ b/dirs-and-confs.txt @@ -7,4 +7,4 @@ ./herd/tests/instructions/AArch64.self ./herd/tests/instructions/AArch64.self/self.cfg ./herd/tests/instructions/AArch64.kvm ./herd/tests/instructions/AArch64.kvm/kvm.cfg ./herd/tests/instructions/AArch64.vmsa+mte ./herd/tests/instructions/AArch64.vmsa+mte/vmsa+mte.cfg -catalogue/aarch64-ifetch/tests catalogue/aarch64-ifetch/cfgs/new-web.cfg \ No newline at end of file +catalogue/aarch64-ifetch/tests catalogue/aarch64-ifetch/cfgs/new-web.cfg diff --git a/litmus/dumpRun.ml b/litmus/dumpRun.ml index eff24b42ba..6e4dbe21a2 100644 --- a/litmus/dumpRun.ml +++ b/litmus/dumpRun.ml @@ -125,26 +125,38 @@ end = struct (List.rev sources) ; fprintf chan "\n" end ; + begin + begin match Cfg.mode with + | Mode.Kvm -> () + | Mode.Std | Mode.PreSi -> + fprintf chan "SRCDIR = $(CURDIR)/..\n" + end ; + fprintf chan "SHARED_SRC_DIR = $(SRCDIR)/shared_lib\n" ; + fprintf chan "GCCOPTS += -I $(SHARED_SRC_DIR)\n\n" + end ; begin match Cfg.mode with | Mode.Std|Mode.PreSi -> () | Mode.Kvm -> let utils = - ["litmus_rand.o"; "utils.o"; "kvm_timeofday.o";] in + ["litmus_rand.c"; "utils.c"; "kvm_timeofday.c";] in let utils = if Cfg.stdio then utils else - "platform_io.o" :: "litmus_io.o" :: utils in + "platform_io.c" :: "litmus_io.c" :: utils in let utils = if flags.Flags.memtag then - "memtag.o"::utils + "memtag.c"::utils else utils in let utils = if flags.Flags.pac then - "auth.o"::utils + "auth.c"::utils else utils in - fprintf chan "UTILS=%s\n" - (String.concat " " utils) + let shared_utils = + List.map (fun util -> "$(SHARED_SRC_DIR)/" ^ util) utils in + fprintf chan "UTILS_SRC = %s\n\n" + (String.concat " " shared_utils) ; + fprintf chan "UTILS_OBJ = $(UTILS_SRC:.c=.o)\n\n" end ; () @@ -167,10 +179,11 @@ end = struct b :: k else k) utils [] in List.iter - (fun u -> - let src = u ^ ".c" and obj = u ^ ".o" in + (fun u -> + let dir_name = if u = "topology" then "" else "$(SHARED_SRC_DIR)/" in + let src = dir_name ^ u ^ ".c" and obj = dir_name ^ u ^ ".o" in fprintf chan "%s: %s\n" obj src ; - fprintf chan "\t$(GCC) $(GCCOPTS) %s-O2 -c %s\n" + fprintf chan "\t$(GCC) $(GCCOPTS) %s-O2 -c -o $@ %s\n" (if TargetOS.is_freebsd Cfg.targetos && u = "affinity" @@ -181,7 +194,7 @@ end = struct utils ; (* UTIL objs *) let utils_objs = - String.concat " " (List.map (fun s -> s ^ ".o") utils) in + String.concat " " (List.map (fun s -> let dir_name = if s = "topology" then "" else "$(SHARED_SRC_DIR)/" in dir_name ^ s ^ ".o") utils) in fprintf chan "UTILS=%s\n\n" utils_objs ; () ;; diff --git a/litmus/libdir/_aarch64/kvm.c.rules b/litmus/libdir/_aarch64/kvm.c.rules index 8d3e609198..80898a453a 100644 --- a/litmus/libdir/_aarch64/kvm.c.rules +++ b/litmus/libdir/_aarch64/kvm.c.rules @@ -15,7 +15,7 @@ clean: %.elf: LDFLAGS = -nostdlib -pie -n -run.elf: run.o $(OBJ) $(UTILS) $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) +run.elf: run.o $(OBJ) $(UTILS_OBJ) $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \ -DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS) $(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \ diff --git a/litmus/libdir/_aarch64/kvm.rules b/litmus/libdir/_aarch64/kvm.rules index 2e52b063da..4f04855e06 100644 --- a/litmus/libdir/_aarch64/kvm.rules +++ b/litmus/libdir/_aarch64/kvm.rules @@ -13,7 +13,7 @@ cleansource: awk -f show.awk $< > $@ %.elf: LDFLAGS = -nostdlib -pie -n -%.elf: %.o $(UTILS) $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) +%.elf: %.o $(UTILS_OBJ) $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \ -DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS) $(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \ @@ -25,3 +25,8 @@ cleansource: $(call arch_elf_check, $^) $(OBJCOPY) -O binary $^ $@ @chmod a-x $@ + +.PRECIOUS: $(UTILS_OBJ) + +$(SHARED_SRC_DIR)/%.o: $(SHARED_SRC_DIR)/%.c + $(CC) $(GCCOPTS) -c -o $@ $< \ No newline at end of file diff --git a/litmus/libdir/_x86_64/kvm.c.rules b/litmus/libdir/_x86_64/kvm.c.rules index 362b57b4ce..b88d41cc26 100644 --- a/litmus/libdir/_x86_64/kvm.c.rules +++ b/litmus/libdir/_x86_64/kvm.c.rules @@ -13,7 +13,7 @@ clean: %.h: %.t sh toh.sh $< > $@ -run.elf: run.o $(OBJ) $(UTILS) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o) +run.elf: run.o $(OBJ) $(UTILS_OBJ) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o) $(CC) $(GCCOPTS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds $(filter %.o, $^) $(FLATLIBS) @chmod a-x $@ diff --git a/litmus/libdir/_x86_64/kvm.rules b/litmus/libdir/_x86_64/kvm.rules index c0cb888eb2..0efe177145 100644 --- a/litmus/libdir/_x86_64/kvm.rules +++ b/litmus/libdir/_x86_64/kvm.rules @@ -12,10 +12,15 @@ cleansource: %.t: %.s awk -f show.awk $< > $@ -%.elf: %.o $(UTILS) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o) +%.elf: %.o $(UTILS_OBJ) $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o) $(CC) $(GCCOPTS) -nostdlib -o $@ -Wl,-T,$(SRCDIR)/x86/flat.lds $(filter %.o, $^) $(FLATLIBS) @chmod a-x $@ %.flat: %.elf $(OBJCOPY) -O elf32-i386 $^ $@ @chmod a-x $@ + +.PRECIOUS: $(UTILS_OBJ) + +$(SHARED_SRC_DIR)/%.o: $(SHARED_SRC_DIR)/%.c + $(CC) $(GCCOPTS) -c -o $@ $< \ No newline at end of file diff --git a/litmus/libdir/kvm-aarch64.cfg b/litmus/libdir/kvm-aarch64.cfg index 1827c8370e..204f09db9d 100644 --- a/litmus/libdir/kvm-aarch64.cfg +++ b/litmus/libdir/kvm-aarch64.cfg @@ -13,7 +13,7 @@ ascall = true mode = kvm delay = 32 makevar = AUXFLAGS=0x0 -makevar = SRCDIR=$(PWD)/.. +makevar = SRCDIR=$(CURDIR)/.. makevar = -include $(SRCDIR)/config.mak makevar = libcflat = $(SRCDIR)/lib/libcflat.a makevar = libeabi = $(SRCDIR)/lib/arm/libeabi.a diff --git a/litmus/litmus.ml b/litmus/litmus.ml index 02c3859897..3008d52bea 100644 --- a/litmus/litmus.ml +++ b/litmus/litmus.ml @@ -379,7 +379,7 @@ let () = let asmcomment = !asmcomment let asmcommentaslabel = !asmcommentaslabel end in - let module T = Top_litmus.Top (Config) (Tar) in + let module T = Top_litmus.Top (Config) (Tar) in T.from_files sources ; if not (Option.is_out ()) then MySys.rmdir outname ; exit 0 diff --git a/litmus/objUtil.ml b/litmus/objUtil.ml index 488b8837a3..06395ff869 100644 --- a/litmus/objUtil.ml +++ b/litmus/objUtil.ml @@ -158,6 +158,9 @@ module Make(O:Config)(Tar:Tar.S) = close_in in_chan ; fnames +(* Reference to the shared library *) + let shared_lib = if Tar.is_archive then "shared_lib/" else "../shared_lib/" + (* Copy lib file *) let cpy ?sub ?prf fnames name ext = do_cpy ?sub ?prf fnames ("_" ^ name) name ext @@ -173,7 +176,7 @@ module Make(O:Config)(Tar:Tar.S) = match O.mode with | Mode.Kvm -> "_kvm" ^ O.platform | Mode.PreSi|Mode.Std -> O.platform in - do_cpy fnames (Filename.concat platform name) name ext + do_cpy fnames (Filename.concat platform name) (shared_lib ^ name) ext let affinity_base () = match O.targetos with | Linux|FreeBsd -> "_linux_affinity" @@ -183,6 +186,9 @@ module Make(O:Config)(Tar:Tar.S) = Warn.fatal "Affinity not implemented for %s" (TargetOS.pp os) let dump flags = + (* Create shared library directory *) + let () = MySys.mkdirp (Tar.outname shared_lib) in + let fnames = [] in let fnames = match O.driver with | Driver.Shell -> fnames @@ -205,34 +211,34 @@ module Make(O:Config)(Tar:Tar.S) = |`BPF | `CPP|`LISA | `JAVA | `ASL -> Warn.fatal "no support for arch '%s'" (Archs.pp O.arch) in let fnames = - let fnames = cpy fnames "litmus_rand" ".c" in - let fnames = cpy fnames "litmus_rand" ".h" in + let fnames = cpy' fnames "litmus_rand" (shared_lib ^ "litmus_rand") ".c" in + let fnames = cpy' fnames "litmus_rand" (shared_lib ^ "litmus_rand") ".h" in let sub = dir_of_sysarch O.sysarch in - let fnames = cpy ~sub:sub fnames "cache" ".h" in + let fnames = cpy' ~sub:sub fnames "cache" (shared_lib ^ "cache") ".h" in fnames in let fnames = if O.stdio then fnames else let fnames = cpy_platform fnames "io" ".c" in let fnames = cpy_platform fnames "io" ".h" in - let fnames = cpy fnames "litmus_io" ".c" in - let fnames = cpy fnames "litmus_io" ".h" in + let fnames = cpy' fnames "litmus_io" (shared_lib ^ "litmus_io") ".c" in + let fnames = cpy' fnames "litmus_io" (shared_lib ^ "litmus_io") ".h" in fnames in let fnames = match O.mode with | Mode.Std -> - let fnames = cpy fnames "utils" ".c" in + let fnames = cpy' fnames "utils" (shared_lib ^ "utils") ".c" in (* Select cached conditional variables, disabled. if O.cached then cpy ~prf:"#define CACHE 1" fnames "utils" ".h" else *) - cpy fnames "utils" ".h" + cpy' fnames "utils" (shared_lib ^ "utils") ".h" | Mode.PreSi -> if do_dynalloc then let fnames = - cpy' ~prf:"#define DYNALLOC 1" fnames "presi" "utils" ".c" in - cpy' ~prf:"#define DYNALLOC 1" fnames "presi" "utils" ".h" + cpy' ~prf:"#define DYNALLOC 1" fnames "presi" (shared_lib ^ "utils") ".c" in + cpy' ~prf:"#define DYNALLOC 1" fnames "presi" (shared_lib ^ "utils") ".h" else - let fnames = cpy' fnames "presi" "utils" ".c" in + let fnames = cpy' fnames "presi" (shared_lib ^ "utils") ".c" in cpy' fnames "presi" "utils" ".h" | Mode.Kvm -> let prf = @@ -240,18 +246,19 @@ module Make(O:Config)(Tar:Tar.S) = "#define KVM 1\n#define DYNALLOC 1" else "#define KVM 1" in - let fnames = cpy' ~prf:prf fnames "presi" "utils" ".c" in - let fnames = cpy' ~prf:prf fnames "presi" "utils" ".h" in - let fnames = cpy fnames "kvm_timeofday" ".h" in + let fnames = cpy' ~prf:prf fnames "presi" (shared_lib ^ "utils") ".c" in + let fnames = cpy' ~prf:prf fnames "presi" (shared_lib ^ "utils") ".h" in + let fnames = cpy' fnames "kvm_timeofday" (shared_lib ^ "kvm_timeofday") ".h" in let module I = Insert(O) in - I.copy "kvm_timeofday.c" Tar.outname ; - I.copy "kvm-headers.h" Tar.outname ; + let tar_outname = (fun str -> Tar.outname (shared_lib ^ str)) in + I.copy "kvm_timeofday.c" tar_outname ; + I.copy "kvm-headers.h" tar_outname ; fnames in let fnames = match O.mode with | Mode.Std -> - let fnames = cpy fnames "outs" ".c" in - let fnames = cpy fnames "outs" ".h" in + let fnames = cpy' fnames "outs" (shared_lib ^ "outs") ".c" in + let fnames = cpy' fnames "outs" (shared_lib ^ "outs") ".h" in fnames | Mode.PreSi|Mode.Kvm -> fnames in @@ -260,23 +267,23 @@ module Make(O:Config)(Tar:Tar.S) = | Affinity.No -> fnames | _ -> let affi = affinity_base () in - let fnames = do_cpy fnames affi "affinity" ".c" in - let fnames = cpy fnames "affinity" ".h" in + let fnames = do_cpy fnames affi (shared_lib ^ "affinity") ".c" in + let fnames = cpy' fnames "affinity" (shared_lib ^ "affinity") ".h" in fnames in let fnames = if flags.Flags.memtag then begin let sub = dir_of_sysarch O.sysarch in - let fnames = cpy ~sub:sub fnames "memtag" ".c" in - let fnames = cpy ~sub:sub fnames "memtag" ".h" in + let fnames = cpy' ~sub:sub fnames "memtag" (shared_lib ^ "memtag") ".c" in + let fnames = cpy' ~sub:sub fnames "memtag" (shared_lib ^ "memtag") ".h" in fnames end else fnames in let fnames = if flags.Flags.pac then let sub = dir_of_sysarch O.sysarch in - let fnames = cpy ~sub:sub fnames "auth" ".c" in - let fnames = cpy ~sub:sub fnames "auth" ".h" in + let fnames = cpy' ~sub:sub fnames "auth" (shared_lib ^ "auth") ".c" in + let fnames = cpy' ~sub:sub fnames "auth" (shared_lib ^ "auth") ".h" in fnames else fnames in fnames diff --git a/litmus/preSi.ml b/litmus/preSi.ml index ffca40cf30..03b6750f4b 100644 --- a/litmus/preSi.ml +++ b/litmus/preSi.ml @@ -685,8 +685,8 @@ module Make let data_zero = SkelUtil.data_symb_id pp_data_zero let dump_data_indices test = - O.f "#define %-25s 0" data_unknown ; - O.f "#define %-25s 1" data_zero ; + O.f "#define %-25s 0" data_unknown ; + O.f "#define %-25s 1" data_zero ; (* Define indices for data *) List.iteri (fun k (a,_) -> @@ -1919,10 +1919,10 @@ module Make O.o "/*************/" ; O.o "" ; if do_ascall then begin - List.iter - (dump_thread_code procs_user env) - test.T.code - end + List.iter + (dump_thread_code procs_user env) + test.T.code + end let dump_run_def env test some_ptr stats procs_user = let faults = U.get_faults test in diff --git a/litmus/skelUtil.ml b/litmus/skelUtil.ml index 4242227c67..099e7454ee 100644 --- a/litmus/skelUtil.ml +++ b/litmus/skelUtil.ml @@ -778,7 +778,7 @@ end end let dump_label_defs lbls = - O.f "#define %-25s 0" (instr_symb_id "UNKNOWN") ; + O.f "#define %-25s 0" (instr_symb_id "UNKNOWN") ; (* Define indices for labels *) List.iteri (fun i (p,lbl) ->