diff --git a/.gitignore b/.gitignore index c65f1221cf..34388ee7f7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ options.inc core ld +oneTBB diff --git a/.gitmodules b/.gitmodules index e145826c42..de4d60e572 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ -[submodule "oneTBB"] - path = oneTBB - url = https://github.com/oneapi-src/oneTBB.git [submodule "mimalloc"] path = mimalloc url = https://github.com/microsoft/mimalloc.git -[submodule "xxHash"] - path = xxHash - url = https://github.com/Cyan4973/xxHash.git diff --git a/Makefile b/Makefile index f4817c4863..3a3994e04d 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,25 @@ -CC=clang -CXX=clang++ - -CURRENT_DIR=$(shell pwd) -TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/) -MALLOC_LIBDIR=$(CURRENT_DIR)/mimalloc/out/release - -CPPFLAGS=-g -IoneTBB/include -IxxHash -pthread -std=c++20 \ - -Wno-deprecated-volatile -Wno-switch \ - -DGIT_HASH=\"$(shell git rev-parse HEAD)\" -LDFLAGS=-fuse-ld=lld -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) \ - -L$(MALLOC_LIBDIR) -Wl,-rpath=$(MALLOC_LIBDIR) \ - -L$(CURRENT_DIR)/xxHash -Wl,-rpath=$(CURRENT_DIR)/xxHash -LIBS=-lcrypto -pthread -ltbb -lmimalloc -lz -lxxhash -ldl -OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o \ - linker_script.o archive_file.o output_file.o subprocess.o gc_sections.o \ - icf.o symbols.o cmdline.o filepath.o glob.o passes.o tar.o compress.o \ - arch_x86_64.o arch_i386.o +CC = clang +CXX = clang++ + +MIMALLOC_LIB = mimalloc/out/release/libmimalloc.a + +CPPFLAGS = -g -Imimalloc/include -pthread -std=c++20 \ + -Wno-deprecated-volatile -Wno-switch \ + -DGIT_HASH=\"$(shell git rev-parse HEAD)\" \ + $(EXTRA_CPPFLAGS) +LDFLAGS = $(EXTRA_LDFLAGS) +LIBS = -lcrypto -pthread -ltbb -lz -lxxhash \ + -Wl,-as-needed -ldl -Wl,-no-as-needed +OBJS = main.o object_file.o input_sections.o output_chunks.o \ + mapfile.o perf.o linker_script.o archive_file.o output_file.o \ + subprocess.o gc_sections.o icf.o symbols.o cmdline.o filepath.o \ + glob.o passes.o tar.o compress.o arch_x86_64.o arch_i386.o PREFIX ?= /usr - DEBUG ?= 0 LTO ?= 0 ASAN ?= 0 TSAN ?= 0 -STATIC ?= 1 ifeq ($(DEBUG), 1) CPPFLAGS += -O0 @@ -39,22 +35,21 @@ endif ifeq ($(ASAN), 1) CPPFLAGS += -fsanitize=address LDFLAGS += -fsanitize=address - STATIC = 0 +else + # By default, we want to use mimalloc as a memory allocator. + # Since replacing the standard malloc is not compatible with ASAN, + # we do that only when ASAN is not enabled. + LDFLAGS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive endif ifeq ($(TSAN), 1) CPPFLAGS += -fsanitize=thread LDFLAGS += -fsanitize=thread - STATIC = 0 -endif - -ifeq ($(STATIC), 1) - CPPFLAGS += -static endif all: mold mold-wrapper.so -mold: $(OBJS) +mold: $(OBJS) $(MIMALLOC_LIB) $(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS) mold-wrapper.so: mold-wrapper.c Makefile @@ -62,13 +57,10 @@ mold-wrapper.so: mold-wrapper.c Makefile $(OBJS): mold.h elf.h Makefile -submodules: - $(MAKE) -C oneTBB - $(MAKE) -C oneTBB extra_inc=big_iron.inc +$(MIMALLOC_LIB): mkdir -p mimalloc/out/release (cd mimalloc/out/release; CFLAGS=-DMI_USE_ENVIRON=0 cmake ../..) $(MAKE) -C mimalloc/out/release - $(MAKE) -C xxHash test: all for i in test/*.sh; do $$i || exit 1; done diff --git a/README.md b/README.md index e7ad147a72..9f8d2f4f56 100644 --- a/README.md +++ b/README.md @@ -62,20 +62,19 @@ Clang. I'm using Ubuntu 20.04 as a development platform. In that environment, you can build mold by the following commands. ``` -$ sudo apt-get install build-essential libstdc++-10-dev clang-10 libssl-dev zlib1g-dev cmake +$ sudo apt-get install build-essential libstdc++-10-dev cmake clang libssl-dev zlib1g-dev libxxhash-dev libtbb-dev $ git clone --recursive https://github.com/rui314/mold.git $ cd mold -$ make submodules $ make ``` The last `make` command creates `mold` executable. -You can build a statically-linked mold executable by substituting the -last `make` with `make STATIC=1`. A statically-linked mold executable -can be copied to any Linux system and run there without copying other -libraries. This is useful if you want to use Ubuntu 20.04 only for -building mold. +If you don't have Ubuntu 20.04, or if for any reason `make` in the +above commands doesn't work for you, you can use Docker to build it in +a Docker environment. To do so, just run `./build-static.sh` in this +directory. The script creates a Ubuntu 20.04 Docker image, install +necessary tools and libraries to it and build mold as a static binary. ## How to use diff --git a/build-static.sh b/build-static.sh new file mode 100755 index 0000000000..77aa0f38ae --- /dev/null +++ b/build-static.sh @@ -0,0 +1,33 @@ +#!/bin/bash -x + +# This is a shell script to build a statically-linked mold +# executable using Docker, so that it is easy to build mold +# on non-Ubuntu 20.04 machines. +# +# A docker image used for building mold is persistent. +# Run `docker image rm mold-build-ubuntu20` to remove the image +# from disk. + +cat < #include @@ -27,6 +26,7 @@ #include #include #include +#include typedef uint8_t u8; typedef uint16_t u16; diff --git a/oneTBB b/oneTBB deleted file mode 160000 index eca91f16d7..0000000000 --- a/oneTBB +++ /dev/null @@ -1 +0,0 @@ -Subproject commit eca91f16d7490a8abfdee652dadf457ec820cc37 diff --git a/xxHash b/xxHash deleted file mode 160000 index ea5393ddb9..0000000000 --- a/xxHash +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ea5393ddb997999aace2be4e101a4efa8e8f3cb3