[klibc] [PATCH v2 2/5] Kbuild: support clang's lld
Bill Wendling
morbo at google.com
Fri Mar 27 15:29:43 PDT 2020
From: Stanislav Fomichev <sdf at google.com>
Clang's lld prefers the use of "-image-base" instead of
"-Ttext-segment".
Signed-off-by: Stanislav Fomichev <sdf at google.com>
Signed-off-by: Bill Wendling <morbo at google.com>
---
Makefile | 3 +++
usr/klibc/arch/i386/MCONFIG | 2 +-
usr/klibc/arch/mips64/MCONFIG | 2 +-
usr/klibc/arch/ppc/MCONFIG | 2 +-
usr/klibc/arch/ppc64/MCONFIG | 2 +-
usr/klibc/arch/riscv64/MCONFIG | 2 +-
usr/klibc/arch/sparc64/MCONFIG | 2 +-
usr/klibc/arch/x86_64/MCONFIG | 2 +-
8 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index c99b962fd2a3..52d7cd2cf791 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,9 @@ export NM := $(KLIBCROSS)nm
export OBJCOPY := $(KLIBCROSS)objcopy
export OBJDUMP := $(KLIBCROSS)objdump
+LLD := $(shell $(LD) --version 2>&1 | grep LLD)
+export IMAGE_BASE=$(if $(LLD),--image-base,-Ttext-segment)
+
NOSTDINC_FLAGS := -nostdlib -nostdinc -isystem $(shell $(CC) -print-file-name=include)
ARCH := $(shell uname -m | sed -e s/i.86/i386/ \
diff --git a/usr/klibc/arch/i386/MCONFIG b/usr/klibc/arch/i386/MCONFIG
index 0704669500f0..baa7e59854f8 100644
--- a/usr/klibc/arch/i386/MCONFIG
+++ b/usr/klibc/arch/i386/MCONFIG
@@ -30,4 +30,4 @@ KLIBCBITSIZE = 32
# This address needs to be reachable using normal inter-module
# calls, and work on the memory models for this architecture
# 96 MB - normal binaries start at 128 MB
-KLIBCSHAREDFLAGS = -Ttext-segment 0x06000000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x06000000
diff --git a/usr/klibc/arch/mips64/MCONFIG b/usr/klibc/arch/mips64/MCONFIG
index 6a4b41b2f85c..3d7f20da08be 100644
--- a/usr/klibc/arch/mips64/MCONFIG
+++ b/usr/klibc/arch/mips64/MCONFIG
@@ -20,4 +20,4 @@ KLIBCBITSIZE = 64
# load address, use the very top of the 256M region (minus 2MB)
#
# Use -Ttext-segment so that the special .MIPS* sections are moved as well.
-KLIBCSHAREDFLAGS = -Ttext-segment 0x12FE00000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x12FE00000
diff --git a/usr/klibc/arch/ppc/MCONFIG b/usr/klibc/arch/ppc/MCONFIG
index 8220f6b93fa4..ec859e8941d9 100644
--- a/usr/klibc/arch/ppc/MCONFIG
+++ b/usr/klibc/arch/ppc/MCONFIG
@@ -20,7 +20,7 @@ KLIBCBITSIZE = 32
# calls, and work on the memory models for this architecture
# 256-16 MB - normal binaries start at 256 MB, and jumps are limited
# to +/- 16 MB
-KLIBCSHAREDFLAGS = -Ttext-segment 0x0f800000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x0f800000
# The asm include files live in asm-powerpc
KLIBCASMARCH = powerpc
diff --git a/usr/klibc/arch/ppc64/MCONFIG b/usr/klibc/arch/ppc64/MCONFIG
index 0315110ca379..442d452bf11b 100644
--- a/usr/klibc/arch/ppc64/MCONFIG
+++ b/usr/klibc/arch/ppc64/MCONFIG
@@ -18,7 +18,7 @@ KLIBCBITSIZE = 64
# calls, and work on the memory models for this architecture
# 256-16 MB - normal binaries start at 256 MB, and jumps are limited
# to +/- 16 MB
-KLIBCSHAREDFLAGS = -Ttext-segment 0x0f000000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x0f000000
# The asm include files live in asm-powerpc
KLIBCASMARCH = powerpc
diff --git a/usr/klibc/arch/riscv64/MCONFIG b/usr/klibc/arch/riscv64/MCONFIG
index 61681509d89d..2ea257548417 100644
--- a/usr/klibc/arch/riscv64/MCONFIG
+++ b/usr/klibc/arch/riscv64/MCONFIG
@@ -17,4 +17,4 @@ endif
KLIBCBITSIZE = 64
# Normal binaries start at 64 KB, so start the libary at 2 MB.
-KLIBCSHAREDFLAGS =-Ttext-segment 0x00200000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x00200000
diff --git a/usr/klibc/arch/sparc64/MCONFIG b/usr/klibc/arch/sparc64/MCONFIG
index c83398559f84..767232fce80e 100644
--- a/usr/klibc/arch/sparc64/MCONFIG
+++ b/usr/klibc/arch/sparc64/MCONFIG
@@ -18,4 +18,4 @@ KLIBCLDFLAGS = -m elf64_sparc
# calls, and work on the memory models for this architecture
# Normal binaries start at 1 MB; the linker wants 1 MB alignment,
# and call instructions have a 30-bit signed offset, << 2.
-KLIBCSHAREDFLAGS = -Ttext-segment 0x80000000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x80000000
diff --git a/usr/klibc/arch/x86_64/MCONFIG b/usr/klibc/arch/x86_64/MCONFIG
index 77e2ad279884..ac1ac074c00a 100644
--- a/usr/klibc/arch/x86_64/MCONFIG
+++ b/usr/klibc/arch/x86_64/MCONFIG
@@ -41,4 +41,4 @@ KLIBCLDFLAGS = -m elf_x86_64
# The old default was max-page-size=0x100000, but that also results
# in a broken layout with binutils 2.30. Since there's no
# architectural page size betwen 4 KB and 2MB, set it to 4 KB.
-KLIBCSHAREDFLAGS = -Ttext-segment 0x00200000 -z max-page-size=0x1000
+KLIBCSHAREDFLAGS = $(IMAGE_BASE) 0x00200000 -z max-page-size=0x1000
--
2.26.0.rc2.310.g2932bb562d-goog
More information about the klibc
mailing list