Skip to content

Commit 9f68d6e

Browse files
committed
Fix link order in cosmopolitan.a
It turned out that the linker was doing the wrong with the amalgamation library concerning weak stubs. A regression test has been added and new binaries have been uploaded to https://justine.lol/cosmopolitan/ Ideally this should be fixed by building a tool that turns multiple .a files into a single .a file with deduplication. As a workaround for now the cosmopolitan.a build is restructured to not include LIBC_STUBS which meant technical debt needed to be paid off where non-stub interfaces were moved to LIBC_INTRIN and LIBC_NEXGEN32E. Thank @PerfectProductions in #31 for the report!
1 parent 04f1d89 commit 9f68d6e

File tree

121 files changed

+295
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+295
-374
lines changed

Makefile

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -236,40 +236,44 @@ loc: o/$(MODE)/tool/build/summy.com
236236
$(XARGS) wc -l | grep total | awk '{print $$1}' | $<
237237

238238
COSMOPOLITAN_OBJECTS = \
239-
APE_LIB \
240-
LIBC \
241-
LIBC_ALG \
242-
LIBC_BITS \
243-
LIBC_CALLS \
244-
LIBC_CALLS_HEFTY \
245239
LIBC_CRYPTO \
246240
LIBC_DNS \
247-
LIBC_ELF \
248-
LIBC_FMT \
249-
LIBC_INTRIN \
250-
LIBC_LOG \
251-
LIBC_MEM \
252-
LIBC_NEXGEN32E \
253-
LIBC_NT \
254-
LIBC_OHMYPLUS \
255-
LIBC_RAND \
256-
LIBC_RUNTIME \
257241
LIBC_SOCK \
258-
LIBC_STDIO \
259-
LIBC_STR \
260-
LIBC_STUBS \
261-
LIBC_SYSV \
262-
LIBC_TIME \
263-
LIBC_TINYMATH \
264-
LIBC_UNICODE \
242+
LIBC_NT_WS2_32 \
243+
LIBC_NT_MSWSOCK \
244+
LIBC_OHMYPLUS \
265245
LIBC_X \
266-
LIBC_ZIPOS \
267-
THIRD_PARTY_COMPILER_RT \
268-
THIRD_PARTY_DLMALLOC \
269246
THIRD_PARTY_GDTOA \
270247
THIRD_PARTY_GETOPT \
248+
LIBC_LOG \
249+
LIBC_UNICODE \
250+
LIBC_TIME \
251+
LIBC_ZIPOS \
252+
THIRD_PARTY_ZLIB \
253+
APE_LIB \
271254
THIRD_PARTY_MUSL \
272-
THIRD_PARTY_REGEX
255+
LIBC_STDIO \
256+
LIBC_CALLS_HEFTY \
257+
THIRD_PARTY_REGEX \
258+
LIBC_ALG \
259+
LIBC_MEM \
260+
THIRD_PARTY_DLMALLOC \
261+
LIBC_BITS \
262+
LIBC_RUNTIME \
263+
LIBC_ELF \
264+
LIBC_CALLS \
265+
LIBC_RAND \
266+
LIBC_SYSV_CALLS \
267+
LIBC_NT_NTDLL \
268+
LIBC_NT_ADVAPI32 \
269+
LIBC_FMT \
270+
THIRD_PARTY_COMPILER_RT \
271+
LIBC_TINYMATH \
272+
LIBC_SYSV \
273+
LIBC_STR \
274+
LIBC_INTRIN \
275+
LIBC_NT_KERNEL32 \
276+
LIBC_NEXGEN32E
273277

274278
COSMOPOLITAN_HEADERS = \
275279
LIBC \
@@ -304,7 +308,9 @@ COSMOPOLITAN_HEADERS = \
304308
THIRD_PARTY_ZLIB \
305309
THIRD_PARTY_REGEX
306310

307-
o/$(MODE)/cosmopolitan.a: $(filter-out o/libc/stubs/exit11.o,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_OBJS)))
311+
o/$(MODE)/cosmopolitan.a.txt:
312+
printf "%s\n" $(call reverse,$(call uniq,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)))))
313+
o/$(MODE)/cosmopolitan.a: $(filter-out o/libc/stubs/exit11.o,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_A_OBJS)))
308314
o/cosmopolitan.h: \
309315
o/$(MODE)/tool/build/rollup.com \
310316
libc/integral/normalize.inc \

ape/lib/apelib.mk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ APE_LIB_A_SRCS = \
1717

1818
APE_LIB_A_OBJS = \
1919
$(APE_LIB_A_SRCS_S:%.S=o/$(MODE)/%.o) \
20-
$(APE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o) \
21-
$(APE_LIB_A_SRCS:%=o/$(MODE)/%.zip.o) \
22-
o/$(MODE)/ape/ape.lds.zip.o \
23-
o/$(MODE)/ape/ape.S.zip.o \
24-
o/$(MODE)/NOTICE.zip.o
20+
$(APE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o)
2521

2622
APE_LIB_A_CHECKS = $(APE_LIB_A_HDRS:%=o/$(MODE)/%.ok)
27-
APE_LIB_A_DIRECTDEPS = LIBC_STR LIBC_STUBS
23+
APE_LIB_A_DIRECTDEPS = LIBC_STR LIBC_NEXGEN32E LIBC_STUBS
2824
APE_LIB_A_DEPS = $(call uniq,$(foreach x,$(APE_LIB_A_DIRECTDEPS),$($(x))))
2925

3026
$(APE_LIB_A): ape/lib/ $(APE_LIB_A).pkg $(APE_LIB_A_OBJS)

build/package

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
if [ "$TOOL_BUILD_PACKAGE" ]; then
66
set -- "$TOOL_BUILD_PACKAGE" "$@"
77
else
8-
if [ -x "o/tool/build/package.com" ]; then
9-
set -- "o/tool/build/package.com" "$@"
8+
if [ -x "o/tool/build/package.com.dbg" ]; then
9+
set -- "o/tool/build/package.com.dbg" "$@"
1010
else
1111
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
1212
CP=${CP:-$(command -v cp) -f} || exit

dsp/bmp/bmp.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DSP_BMP_A_SRCS = \
1616
$(DSP_BMP_A_SRCS_C)
1717

1818
DSP_BMP_A_OBJS = \
19-
$(DSP_BMP_A_SRCS:%=o/$(MODE)/%.zip.o) \
2019
$(DSP_BMP_A_SRCS_S:%.S=o/$(MODE)/%.o) \
2120
$(DSP_BMP_A_SRCS_C:%.c=o/$(MODE)/%.o)
2221

dsp/core/core.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DSP_CORE_A_SRCS = \
1616
$(DSP_CORE_A_SRCS_C)
1717

1818
DSP_CORE_A_OBJS = \
19-
$(DSP_CORE_A_SRCS:%=o/$(MODE)/%.zip.o) \
2019
$(DSP_CORE_A_SRCS_S:%.S=o/$(MODE)/%.o) \
2120
$(DSP_CORE_A_SRCS_C:%.c=o/$(MODE)/%.o)
2221

dsp/mpeg/mpeg.mk

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DSP_MPEG_A_SRCS = \
1616
$(DSP_MPEG_A_SRCS_C)
1717

1818
DSP_MPEG_A_OBJS = \
19-
$(DSP_MPEG_A_SRCS:%=o/$(MODE)/%.zip.o) \
2019
$(DSP_MPEG_A_SRCS_S:%.S=o/$(MODE)/%.o) \
2120
$(DSP_MPEG_A_SRCS_C:%.c=o/$(MODE)/%.o)
2221

@@ -26,19 +25,20 @@ DSP_MPEG_A_CHECKS = \
2625

2726
DSP_MPEG_A_DIRECTDEPS = \
2827
LIBC_CALLS \
28+
LIBC_FMT \
29+
LIBC_INTRIN \
2930
LIBC_LOG \
30-
LIBC_RUNTIME \
31-
LIBC_TINYMATH \
32-
LIBC_TIME \
33-
LIBC_STUBS \
34-
LIBC_STR \
31+
LIBC_LOG \
32+
LIBC_MEM \
3533
LIBC_NEXGEN32E \
34+
LIBC_RUNTIME \
3635
LIBC_STDIO \
36+
LIBC_STR \
37+
LIBC_STUBS \
3738
LIBC_SYSV \
38-
LIBC_MEM \
39-
LIBC_LOG \
40-
LIBC_FMT \
41-
LIBC_UNICODE \
39+
LIBC_TIME \
40+
LIBC_TINYMATH \
41+
LIBC_UNICODE
4242

4343
DSP_MPEG_A_DEPS := \
4444
$(call uniq,$(foreach x,$(DSP_MPEG_A_DIRECTDEPS),$($(x))))

dsp/scale/scale.mk

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DSP_SCALE_A_SRCS = \
1616
$(DSP_SCALE_A_SRCS_C)
1717

1818
DSP_SCALE_A_OBJS = \
19-
$(DSP_SCALE_A_SRCS:%=o/$(MODE)/%.zip.o) \
2019
$(DSP_SCALE_A_SRCS_S:%.S=o/$(MODE)/%.o) \
2120
$(DSP_SCALE_A_SRCS_C:%.c=o/$(MODE)/%.o)
2221

@@ -27,14 +26,15 @@ DSP_SCALE_A_CHECKS = \
2726
DSP_SCALE_A_DIRECTDEPS = \
2827
DSP_CORE \
2928
LIBC_INTRIN \
30-
LIBC_NEXGEN32E \
31-
LIBC_TINYMATH \
32-
LIBC_TIME \
33-
LIBC_RUNTIME \
3429
LIBC_LOG \
3530
LIBC_MEM \
36-
LIBC_X \
37-
LIBC_STUBS
31+
LIBC_NEXGEN32E \
32+
LIBC_RUNTIME \
33+
LIBC_STUBS \
34+
LIBC_STUBS \
35+
LIBC_TIME \
36+
LIBC_TINYMATH \
37+
LIBC_X
3838

3939
DSP_SCALE_A_DEPS := \
4040
$(call uniq,$(foreach x,$(DSP_SCALE_A_DIRECTDEPS),$($(x))))

dsp/tty/tty.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DSP_TTY_A_SRCS = \
1616
$(DSP_TTY_A_SRCS_C)
1717

1818
DSP_TTY_A_OBJS = \
19-
$(DSP_TTY_A_SRCS:%=o/$(MODE)/%.zip.o) \
2019
$(DSP_TTY_A_SRCS_S:%.S=o/$(MODE)/%.o) \
2120
$(DSP_TTY_A_SRCS_C:%.c=o/$(MODE)/%.o)
2221

@@ -29,6 +28,7 @@ DSP_TTY_A_DIRECTDEPS = \
2928
LIBC_ALG \
3029
LIBC_CALLS \
3130
LIBC_FMT \
31+
LIBC_INTRIN \
3232
LIBC_LOG \
3333
LIBC_RUNTIME \
3434
LIBC_MEM \

examples/examples.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ EXAMPLES_MAINS = \
1919
$(EXAMPLES_MAINS_CC)
2020

2121
EXAMPLES_OBJS = \
22-
$(EXAMPLES_SRCS:%=o/$(MODE)/%.zip.o) \
2322
$(EXAMPLES_MAINS_S:%.S=o/$(MODE)/%.o) \
2423
$(EXAMPLES_MAINS_C:%.c=o/$(MODE)/%.o) \
2524
$(EXAMPLES_MAINS_CC:%.cc=o/$(MODE)/%.o)
@@ -47,6 +46,7 @@ EXAMPLES_DIRECTDEPS = \
4746
LIBC_CALLS \
4847
LIBC_CALLS_HEFTY \
4948
LIBC_FMT \
49+
LIBC_INTRIN \
5050
LIBC_LOG \
5151
LIBC_LOG_ASAN \
5252
LIBC_MEM \

examples/package/build.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ EXAMPLES_PACKAGE_BINS = \
3535
# Remaps source file names to object names.
3636
# Also asks a wildcard rule to automatically run tool/build/zipobj.c
3737
EXAMPLES_PACKAGE_OBJS = \
38-
$(EXAMPLES_PACKAGE_SRCS:%.c=o/$(MODE)/%.o) \
39-
$(EXAMPLES_PACKAGE_SRCS:%=o/$(MODE)/%.zip.o)
38+
$(EXAMPLES_PACKAGE_SRCS:%.c=o/$(MODE)/%.o)
4039

4140
# Lists packages whose symbols are or may be directly referenced here.
4241
# Note that linking stubs is always a good idea due to synthetic code.

0 commit comments

Comments
 (0)