Skip to content

Commit df5ca01

Browse files
committed
Distinguish HOST_RPATH, TARGET_RPATH; cleanup mk files for stage1.
Two line summary: Distinguish HOST_RPATH and TARGET_RPATH; added RPATH_LINK_SEARCH; skip tests broken in stage1; general cleanup. What this commit does: * Pass both of the (newly introduced) HOST and TARGET rpath setup vars to `maketest.py` * Update `maketest.py` to no longer update the LD_LIBRARY_PATH itself Instead, it passes along the HOST and TARGET rpath setup vars in environment variables `HOST_RPATH_ENV` and `TARGET_RPATH_ENV` * Cleanup: Distinguish in tools.mk between the command to run (`RUN`) and the file to generate to drive that command (`RUN_BINFILE`). The main thing this enables is that `RUN` can now setup the `TARGET_RPATH_ENV` without having to dirty up the runner code in each of the `run-make` Makefiles. * Pass stage to maketest.py; it in turn passes it (via an env var) to run-make tests. This allows the run-make tests to selectively change behavior (e.g. turn themselves off) to deal with incompatibilities with e.g. stage1. * Factored out commands to delete dylib/rlib into REMOVE_DYLIBS/REMOVE_RLIBS. There were places where we were only calling `rm $(call DYLIB,foo)` even though we really needed to get rid of the whole glob (at least based on alex's findings on rust-lang#13753 that removing the symlink does not suffice). Therefore rather than peppering the code with the awkward `rm $(TMPDIR)/$(call DYLIB_GLOB,foo)`, I instead introduced a common `REMOVE_DYLIBS` user function that expands into that when called. After I adding an analogous `REMOVE_RLIBS`, I changed all of the existing calls that rm dylibs or rlibs to use these routines instead. Note that the latter is not a true refactoring since I may have changed cases where it was our intent to only remove the sym-link. (But if that is the case, then we need to more deeply investigate alex's findings on rust-lang#13753 where the system was still dynamically loading up the non-symlinked libraries that it finds on the load path.) * Added RPATH_LINK_SEARCH command and use it on Linux. On some platforms, namely Linux, when you have libboot.so that has its internal rpath set (to e.g. $(ORIGIN)/path/to/HOSTDIR), the linker still complains when you do the link step and it does not know where to find libraries that libboot.so depends upon that live in HOSTDIR (think e.g. librustuv.so). As far as I can tell, the GNU linker will consult the LD_LIBRARY_PATH as part of the linking process to find such libraries. But if you want to be more careful and not override LD_LIBRARY_PATH for the `gcc` invocation, then you need some other way to tell the linker where it can find the libraries that libboot.so needs. The solution to this on Linux is the `-Wl,-rpath-link` command line option. However, this command line option does not exist on Mac OS X, (which appears to be figuring out how to resolve the libboot.dylib dependency by some other means, perhaps by consulting the rpath setting within libboot.dylib). So, in order to abstract over this distinction, I added the RPATH_LINK_SEARCH macro to the run-make infrastructure and added calls to it where necessary to get Linux working. On architectures other than Linux, the macro expands to nothing.
1 parent d6f506b commit df5ca01

File tree

19 files changed

+72
-35
lines changed

19 files changed

+72
-35
lines changed

mk/tests.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,9 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
951951
"$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
952952
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
953953
"$$(TESTNAME)" \
954-
"$$(RPATH_VAR$(1)_T_$(2)_H_$(3))"
954+
"$$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))" \
955+
"$$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))" \
956+
$(1)
955957
@touch $$@
956958
else
957959
# FIXME #11094 - The above rule doesn't work right for multiple targets

src/etc/maketest.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,27 @@ def putenv(name, value):
3030
value = normalize_path(value)
3131
os.putenv(name, value)
3232

33+
def convert_path_spec(name_and_value):
34+
name = name_and_value.split('=')[0]
35+
value = name_and_value.split('=')[1]
36+
if os.name == 'nt' and name != 'PATH':
37+
value = ":".join(normalize_path(v) for v in value.split(";"))
38+
return (name, value)
39+
40+
def put_delayed_env_setting(carrier_name, setting):
41+
if setting != '':
42+
delayed_name, value = convert_path_spec(setting)
43+
os.putenv(carrier_name, delayed_name + '=' + value)
3344

3445
make = sys.argv[2]
3546
putenv('RUSTC', os.path.abspath(sys.argv[3]))
3647
putenv('TMPDIR', os.path.abspath(sys.argv[4]))
3748
putenv('CC', sys.argv[5])
3849
putenv('RUSTDOC', os.path.abspath(sys.argv[6]))
3950
filt = sys.argv[7]
40-
ldpath = sys.argv[8]
41-
if ldpath != '':
42-
name = ldpath.split('=')[0]
43-
value = ldpath.split('=')[1]
44-
if os.name == 'nt' and name != 'PATH':
45-
value = ":".join(normalize_path(v) for v in value.split(";"))
46-
os.putenv(name, value)
51+
put_delayed_env_setting('HOST_RPATH_ENV', sys.argv[8])
52+
put_delayed_env_setting('TARGET_RPATH_ENV', sys.argv[9])
53+
putenv('RUST_BUILD_STAGE', sys.argv[10])
4754

4855
if not filt in sys.argv[1]:
4956
sys.exit(0)
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
-include ../tools.mk
22

3+
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4+
# This overrides the LD_LIBRARY_PATH for RUN
5+
TARGET_RPATH_ENV:=$(TARGET_RPATH_ENV):$(TMPDIR)
6+
37
all:
8+
env
49
$(RUSTC) lib.rs
510
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
6-
$(CC) main.c -o $(call RUN,main) -lboot
11+
$(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
712
$(call RUN,main)
8-
rm $(call DYLIB,boot)
13+
$(call REMOVE_DYLIBS,boot)
914
$(call FAIL,main)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
-include ../tools.mk
22

3+
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4+
# This overrides the LD_LIBRARY_PATH for RUN
5+
TARGET_RPATH_ENV:=$(TARGET_RPATH_ENV):$(TMPDIR)
6+
37
all:
48
$(RUSTC) lib.rs
59
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
6-
$(CC) main.c -o $(call RUN,main) -lboot
10+
$(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
711
$(call RUN,main)
8-
rm $(call DYLIB,boot)
12+
$(call REMOVE_DYLIBS,boot)
913
$(call FAIL,main)

src/test/run-make/c-dynamic-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ all: $(call DYLIB,cfoo)
99
$(RUSTC) foo.rs
1010
$(RUSTC) bar.rs
1111
$(call RUN,bar)
12-
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
12+
$(call REMOVE_DYLIBS,cfoo)
1313
$(call FAIL,bar)
1414
endif
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-include ../tools.mk
22

3+
# This overrides the LD_LIBRARY_PATH for RUN
4+
TARGET_RPATH_ENV:=$(TARGET_RPATH_ENV):$(TMPDIR)
5+
36
# This hits an assertion in the linker on older versions of osx apparently
47
ifeq ($(shell uname),Darwin)
58
all:
@@ -8,7 +11,7 @@ else
811
all: $(call DYLIB,cfoo)
912
$(RUSTC) foo.rs
1013
$(RUSTC) bar.rs
11-
LD_LIBRARY_PATH=$(TMPDIR) $(call RUN,bar)
12-
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
14+
$(call RUN,bar)
15+
$(call REMOVE_DYLIBS,cfoo)
1316
$(call FAIL,bar)
1417
endif
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
-include ../tools.mk
22

3+
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4+
35
all:
46
$(RUSTC) foo.rs
57
ln -s $(call DYLIB,foo-*) $(call DYLIB,foo)
6-
$(CC) bar.c -lfoo -o $(call RUN,bar) -Wl,-rpath,$(TMPDIR)
8+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -Wl,-rpath,$(TMPDIR)
79
$(call RUN,bar)
8-
rm $(call DYLIB,foo)
10+
$(call REMOVE_DYLIBS,foo)
911
$(call FAIL,bar)

src/test/run-make/c-link-to-rust-staticlib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ifneq ($(shell uname),FreeBSD)
1111
all:
1212
$(RUSTC) foo.rs
1313
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
14-
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
14+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
1515
$(call RUN,bar)
1616
rm $(call STATICLIB,foo*)
1717
$(call RUN,bar)

src/test/run-make/c-static-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ all: $(call STATICLIB,cfoo)
55
$(RUSTC) bar.rs
66
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
77
$(call RUN,bar)
8-
rm $(TMPDIR)/$(call DYLIB_GLOB,foo)
8+
$(call REMOVE_DYLIBS,foo)
99
$(call FAIL,bar)

src/test/run-make/c-static-rlib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
all: $(call STATICLIB,cfoo)
44
$(RUSTC) foo.rs
55
$(RUSTC) bar.rs
6-
rm $(TMPDIR)/$(call RLIB_GLOB,foo)
6+
$(call REMOVE_RLIBS,foo)
77
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
88
$(call RUN,bar)

src/test/run-make/dylib-chain/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ all:
66
$(RUSTC) m3.rs
77
$(RUSTC) m4.rs
88
$(call RUN,m4)
9-
rm $(TMPDIR)/$(call DYLIB_GLOB,m1)
10-
rm $(TMPDIR)/$(call DYLIB_GLOB,m2)
11-
rm $(TMPDIR)/$(call DYLIB_GLOB,m3)
9+
$(call REMOVE_DYLIBS,m1)
10+
$(call REMOVE_DYLIBS,m2)
11+
$(call REMOVE_DYLIBS,m3)
1212
$(call FAIL,m4)

src/test/run-make/extern-fn-reachable/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-include ../tools.mk
22

3+
# This overrides the LD_LIBRARY_PATH for RUN
4+
TARGET_RPATH_ENV:=$(TARGET_RPATH_ENV):$(TMPDIR)
5+
36
all:
47
$(RUSTC) dylib.rs -o $(TMPDIR)/libdylib.so
58
$(RUSTC) main.rs

src/test/run-make/lto-smoke-c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ CC := $(CC:-g=)
1919
all:
2020
$(RUSTC) foo.rs -Z lto
2121
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
22-
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
22+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
2323
$(call RUN,bar)

src/test/run-make/missing-crate-dependency/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
all:
44
$(RUSTC) --crate-type=rlib crateA.rs
55
$(RUSTC) --crate-type=rlib crateB.rs
6-
rm $(TMPDIR)/$(call RLIB_GLOB,crateA)
6+
$(call REMOVE_RLIBS,crateA)
77
# Ensure crateC fails to compile since dependency crateA is missing
88
$(RUSTC) crateC.rs 2>&1 | \
99
grep "error: can't find crate for \`crateA\` which \`crateB\` depends on"

src/test/run-make/mixing-libs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ all:
55
$(RUSTC) dylib.rs
66
$(RUSTC) rlib.rs --crate-type=dylib
77
$(RUSTC) dylib.rs
8-
rm $(call DYLIB,rlib-*)
8+
$(call REMOVE_DYLIBS,rlib)
99
$(RUSTC) prog.rs && exit 1 || exit 0

src/test/run-make/obey-crate-type-flag/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# fail if an rlib was built
88
all:
99
$(RUSTC) test.rs
10-
rm $(TMPDIR)/$(call RLIB_GLOB,test)
11-
rm $(TMPDIR)/$(call DYLIB_GLOB,test)
10+
$(call REMOVE_RLIBS,test)
11+
$(call REMOVE_DYLIBS,test)
1212
$(RUSTC) --crate-type dylib test.rs
13-
rm $(TMPDIR)/$(call RLIB_GLOB,test) && exit 1 || exit 0
13+
$(call REMOVE_RLIBS,test) && exit 1 || exit 0

src/test/run-make/output-type-permutations/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
all:
44
$(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib
5-
rm $(TMPDIR)/$(call RLIB_GLOB,bar)
6-
rm $(TMPDIR)/$(call DYLIB_GLOB,bar)
5+
$(call REMOVE_RLIBS,bar)
6+
$(call REMOVE_DYLIBS,bar)
77
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
88
$(RUSTC) foo.rs --crate-type=bin
99
rm $(TMPDIR)/$(call BIN,bar)
@@ -41,4 +41,4 @@ all:
4141
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
4242
rm $(TMPDIR)/bar.bc
4343
rm $(TMPDIR)/foo.bc
44-
rm $(TMPDIR)/$(call RLIB_GLOB,bar)
44+
$(call REMOVE_RLIBS,bar)

src/test/run-make/prefer-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ all:
55
$(RUSTC) foo.rs -C prefer-dynamic
66
$(call RUN,foo)
77
rm $(TMPDIR)/*bar*
8-
$(call FAILS,foo)
8+
$(call FAIL,foo)

src/test/run-make/tools.mk

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ export DYLD_LIBRARY_PATH:=$(TMPDIR):$(DYLD_LIBRARY_PATH)
44
RUSTC := $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
55
CC := $(CC) -L $(TMPDIR)
66

7-
RUN = $(TMPDIR)/$(1)
8-
FAILS = $(TMPDIR)/$(1) && exit 1 || exit 0
7+
# This is the name of the binary we will generate and run; use this
8+
# e.g. for `$(CC) -o $(RUN_BINFILE)`.
9+
RUN_BINFILE = $(TMPDIR)/$(1)
10+
# This the basic way we will invoke the generated binary. It sets the
11+
# LD_LIBRARY_PATH environment variable before running the binary.
12+
RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
13+
FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
914

1015
RLIB_GLOB = lib$(1)*.rlib
1116
STATICLIB = $(TMPDIR)/lib$(1).a
@@ -20,18 +25,24 @@ endif
2025
ifeq ($(UNAME),Darwin)
2126
DYLIB_GLOB = lib$(1)*.dylib
2227
DYLIB = $(TMPDIR)/lib$(1).dylib
28+
RPATH_LINK_SEARCH =
2329
else
2430
ifdef IS_WINDOWS
2531
DYLIB_GLOB = $(1)*.dll
2632
DYLIB = $(TMPDIR)/$(1).dll
2733
BIN = $(1).exe
34+
RPATH_LINK_SEARCH =
2835
export PATH := $(PATH):$(LD_LIBRARY_PATH)
2936
else
3037
DYLIB_GLOB = lib$(1)*.so
3138
DYLIB = $(TMPDIR)/lib$(1).so
39+
RPATH_LINK_SEARCH = -Wl,-rpath-link=$(1)
3240
endif
3341
endif
3442

43+
REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
44+
REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
45+
3546
%.a: %.o
3647
ar crus $@ $<
3748
%.dylib: %.o

0 commit comments

Comments
 (0)