[klibc] [kvm-unit-tests PATCH v3 2/4] Kbuild: support clang's lld
Bill Wendling
morbo at google.com
Sun Mar 29 04:38:31 PDT 2020
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 | 5 +++--
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, 12 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index c99b962f..c8325154 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 LD_IMAGE_BASE_OPT=$(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 07046695..24ae50bc 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 = $(LD_IMAGE_BASE_OPT) 0x06000000
diff --git a/usr/klibc/arch/mips64/MCONFIG b/usr/klibc/arch/mips64/MCONFIG
index 6a4b41b2..b35f75b4 100644
--- a/usr/klibc/arch/mips64/MCONFIG
+++ b/usr/klibc/arch/mips64/MCONFIG
@@ -19,5 +19,6 @@ KLIBCBITSIZE = 64
# 256M aligned region. Since we can't put ourselves below the normal
# 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
+# Use -Ttext-segment/--image_base so that the special .MIPS* sections
+# are moved as well.
+KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x12FE00000
diff --git a/usr/klibc/arch/ppc/MCONFIG b/usr/klibc/arch/ppc/MCONFIG
index 8220f6b9..dd239605 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 = $(LD_IMAGE_BASE_OPT) 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 0315110c..be15c32d 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 = $(LD_IMAGE_BASE_OPT) 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 61681509..a6228d85 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 = $(LD_IMAGE_BASE_OPT) 0x00200000
diff --git a/usr/klibc/arch/sparc64/MCONFIG b/usr/klibc/arch/sparc64/MCONFIG
index c8339855..459d2217 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 = $(LD_IMAGE_BASE_OPT) 0x80000000
diff --git a/usr/klibc/arch/x86_64/MCONFIG b/usr/klibc/arch/x86_64/MCONFIG
index 7eed8847..2bad5b90 100644
--- a/usr/klibc/arch/x86_64/MCONFIG
+++ b/usr/klibc/arch/x86_64/MCONFIG
@@ -37,4 +37,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 = $(LD_IMAGE_BASE_OPT) 0x00200000 -z max-page-size=0x1000
--
2.26.0.rc2.310.g2932bb562d-goog
More information about the klibc
mailing list