Skip to content

Commit 10994e1

Browse files
yamahatamkow
authored andcommitted
[Makefile] Use symlinks instead of cp to populate Runtime dir
Currently cp to Runtime dir is used. Sometimes it is confusing when binaries are re-built under Pal or LibOS. Symlink is better, so use it instead. - It's easy to understand where a file under Runtime dir comes from - It's easy to understand in which directory to run `make` - If cp is used, it's quite easy to test old binary under Runtime. This patch create ln_sf rule and use it instead of cp and applies to other recipe with cp. In this context, creating symlink of glibc libraries is mess. This patch also cleans it up to use Makefile instead of embedding the logic into python script. Signed-off-by: Isaku Yamahata <[email protected]>
1 parent 1b3b348 commit 10994e1

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

LibOS/Makefile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,32 @@ GLIBC_SRC = glibc-2.19
77
GLIBC_CHECKSUM = 18ad6db70724699d264add80b1f813630d0141cf3a3558b4e1a7c15f6beac796
88
SHIM_DIR = shim
99
BUILD_DIR = glibc-build
10-
GLIBC_TARGET = $(addprefix $(BUILD_DIR)/,libc.so.6 ld-linux-x86-64.so.2 libpthread.so.0 libm.so.6 libdl.so.2 libutil.so.1 crt1.o crti.o crtn.o liblibos.so.1 libnss_dns.so.2 libresolv.so.2)
10+
RUNTIME_DIR = $(CURDIR)/../Runtime
11+
GLIBC_LIBS = \
12+
csu/crt1.o \
13+
csu/crti.o \
14+
csu/crtn.o \
15+
dlfcn/libdl.so.2 \
16+
elf/ld-linux-x86-64.so.2 \
17+
libc.so \
18+
libc.so.6 \
19+
libos/liblibos.so.1 \
20+
login/libutil.so.1 \
21+
math/libm.so.6 \
22+
nptl/libpthread.so.0 \
23+
nptl_db/libthread_db.so.1 \
24+
resolv/libnss_dns.so.2 \
25+
resolv/libresolv.so.2 \
26+
rt/librt.so.1
27+
GLIBC_TARGET = $(addprefix $(BUILD_DIR)/, $(GLIBC_LIBS))
28+
GLIBC_RUNTIME = $(addprefix $(RUNTIME_DIR)/, $(notdir $(GLIBC_TARGET)))
1129

1230
.PHONY: all
13-
all: $(GLIBC_TARGET)
31+
all: $(GLIBC_TARGET) $(GLIBC_RUNTIME)
1432
$(MAKE) -C $(SHIM_DIR) all
1533

34+
include ../Makefile.rules
35+
1636
.PHONY: format
1737
format:
1838
$(MAKE) -C $(SHIM_DIR) format
@@ -49,6 +69,13 @@ else
4969
./buildglibc.py --quiet
5070
endif
5171

72+
define LN_SF_TO_RUNTIME_DIR_template =
73+
$(RUNTIME_DIR)/$(notdir $(1)): $(1)
74+
$$(call cmd,ln_sf)
75+
endef
76+
77+
$(foreach lib,$(GLIBC_TARGET),$(eval $(call LN_SF_TO_RUNTIME_DIR_template,$(lib))))
78+
5279
GLIBC_MIRRORS ?= https://ftp.gnu.org/gnu/ \
5380
https://mirrors.kernel.org/gnu/ \
5481
https://mirrors.ocf.berkeley.edu/gnu/

LibOS/buildglibc.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,3 @@ def appendText(filename, text) :
116116
if numCPUs == 0:
117117
numCPUs = 1
118118
replaceAll('Makefile', r'# PARALLELMFLAGS = -j4', r'PARALLELMFLAGS = -j{0}'.format(numCPUs))
119-
120-
121-
link_binaries = [ ( 'elf', 'ld-linux-x86-64.so.2' ),
122-
( 'nptl', 'libpthread.so.0' ),
123-
( '', 'libc.so' ),
124-
( '', 'libc.so.6' ),
125-
( 'nptl_db','libthread_db.so.1' ),
126-
( 'math', 'libm.so.6' ),
127-
( 'dlfcn', 'libdl.so.2' ),
128-
( 'login', 'libutil.so.1' ),
129-
( 'csu', 'crt1.o' ),
130-
( 'csu', 'crti.o' ),
131-
( 'csu', 'crtn.o' ),
132-
( 'rt', 'librt.so.1' ),
133-
( 'resolv', 'libnss_dns.so.2' ),
134-
( 'resolv', 'libresolv.so.2' ),
135-
( 'libos', 'liblibos.so.1' ) ]
136-
137-
if True:
138-
139-
for (dir, bin) in link_binaries:
140-
if os.path.lexists(installDir + '/' + bin):
141-
continue
142-
143-
print installDir + '/' + bin + ' -> ' + buildDir + '/' + dir + '/' + bin
144-
os.symlink(os.path.relpath(buildDir + '/' + dir + '/' + bin, installDir), installDir + '/' + bin)

LibOS/shim/src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ CFLAGS += -DPROFILE
7171
endif
7272

7373
$(files_to_install): $(RUNTIME_DIR)/%: %
74-
cp -f $< $@
74+
$(call cmd,ln_sf)
7575

7676
ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
7777
libsysdb.so: $(addsuffix .o,$(objs)) $(filter %.map %.lds,$(LDFLAGS)) \
@@ -87,7 +87,7 @@ libsysdb_debug.so: $(addsuffix .o,$(filter-out syscallas,$(objs))) \
8787

8888
.lib/host_endian.h: ../../../Pal/src/host/$(PAL_HOST)/host_endian.h
8989
@mkdir -p .lib
90-
cp -f $< $@
90+
$(call cmd,ln_sf)
9191

9292
.PHONY: $(graphene_lib)
9393
$(graphene_lib): .lib/host_endian.h

Makefile.rules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ quiet_cmd_asm_offsets_h = [ $@ ]
4444
asm-offsets.h: asm-offsets.s
4545
$(call cmd,asm_offsets_h)
4646
CLEAN_FILES += asm-offests.h
47+
48+
49+
quiet_cmd_ln_sf = [ $@ ]
50+
cmd_ln_sf = ln -sf $(abspath $<) $@

Pal/src/Makefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export PAL_DIR = $(CURDIR)
22
export RUNTIME_DIR = $(CURDIR)/../../Runtime
33

4+
include ../../Makefile.rules
45
include Makefile.Host
56

67
# Customizable PAL Targets
@@ -85,7 +86,7 @@ all: $(files_to_build) $(files_to_install)
8586

8687
$(LIB_DIR)/host_endian.h: $(HOST_DIR)/host_endian.h
8788
@mkdir -p $(LIB_DIR)
88-
cp -f $< $@
89+
$(call cmd,ln_sf)
8990

9091
.PHONY: $(host_lib) $(graphene_lib) $(pal_lib) $(pal_sec)
9192

@@ -98,7 +99,7 @@ $(host_lib): $(graphene_lib)
9899
$(pal_loader) $(pal_sec): $(host_lib)
99100

100101
$(runtime_loader): $(pal_loader)
101-
cp -f $< $@
102+
$(call cmd,ln_sf)
102103

103104
ifneq ($(pal_lib),)
104105
$(pal_lib): $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(objs))) \
@@ -107,24 +108,20 @@ $(pal_lib): $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(objs))) \
107108
$(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix)
108109

109110
$(runtime_lib): $(pal_lib)
110-
cp -f $< $@
111+
$(call cmd,ln_sf)
111112
endif
112113

113114
ifneq ($(pal_sec),)
114115
$(pal_sec): $(graphene_lib)
115116
@[ ! -d security/$(PAL_HOST) ] || $(MAKE) -C security/$(PAL_HOST)
116117

117118
$(runtime_sec): $(pal_sec)
118-
cp -f $< $@
119+
$(call cmd,ln_sf)
119120
endif
120121

121122
ifneq ($(pal_gdb),)
122123
$(runtime_gdb): $(pal_gdb)
123-
ifeq ($(abspath $(pal_gdb)),$(pal_gdb))
124-
ln -sf $< $@
125-
else
126-
ln -sf ../Pal/src/$< $@
127-
endif
124+
$(call cmd,ln_sf)
128125
endif
129126

130127
ifneq ($(pal_lib_post),)

0 commit comments

Comments
 (0)