History log of /netbsd-current/libexec/ld.elf_so/Makefile
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.149 19-Jan-2024 christos

use header decl of __fork()


# 1.148 07-Oct-2023 rin

Drop -O[01] hacks for vax; no longer necessary for patched GCC 10

PR port-vax/57646: Import major vax toolchain fix by Kalvis Duckmanton

XXXRO: GCC 12 may require hacks for a while, but it turned out that
GCC 12 should be treated differently from older versions; a lot of new
files need -O[01] flags, while some may no longer require it.

I will take a look later.

Note that these hacks are not required if Kalvis's patches for GCC 12
are applied.

Keep doc/HACKS entries for a while (will be sync with update for GCC 12).

diff --git a/crypto/external/bsd/openssh/lib/Makefile b/crypto/external/bsd/openssh/lib/Makefile
index 96a93f5e396..4e38be1b642 100644
--- a/crypto/external/bsd/openssh/lib/Makefile
+++ b/crypto/external/bsd/openssh/lib/Makefile
@@ -117,12 +117,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
# XXX
COPTS.channels.c+= -fno-strict-aliasing

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.poly1305.c+= -O0
-COPTS.umac.c+= -O0
-.endif
-
COPTS.hostfile.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.sshkey.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.cipher.c+= -Wno-error=deprecated-declarations
diff --git a/distrib/utils/x_ping/Makefile b/distrib/utils/x_ping/Makefile
index f1c452a0d60..8ee77580a3f 100644
--- a/distrib/utils/x_ping/Makefile
+++ b/distrib/utils/x_ping/Makefile
@@ -12,10 +12,6 @@ CPPFLAGS+= -I${SRCDIR} -DCRUNCHOPS
DPADD= ${LIBM}
LDADD= -lm

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>

.PATH: ${SRCDIR}
diff --git a/external/apache2/argon2/lib/libargon2/Makefile.inc b/external/apache2/argon2/lib/libargon2/Makefile.inc
index d3f4470c6c7..6a1dd146d7d 100644
--- a/external/apache2/argon2/lib/libargon2/Makefile.inc
+++ b/external/apache2/argon2/lib/libargon2/Makefile.inc
@@ -16,7 +16,3 @@ CFLAGS+= -pthread
LDADD+=-lpthread
DPADD+=${LIBPTHREAD}
.endif
-
-.if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-.endif
diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc
index 2f524358f46..d5da774f293 100644
--- a/external/bsd/jemalloc/lib/Makefile.inc
+++ b/external/bsd/jemalloc/lib/Makefile.inc
@@ -53,12 +53,6 @@ COPTS.ctl.c+=-Wno-error=stack-protector
COPTS.stats.c+=-Wno-error=stack-protector
COPTS.tcache.c+=-Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-# in merge_overlapping_regs, at regrename.c
-COPTS.arena.c+=-O0
-COPTS.extent.c+=-O0
-.endif
-
SRCS+=${JEMALLOC_SRCS}

jemalloc.d jemalloc.pico jemalloc.o jemalloc.ln jemalloc.po jemalloc.go: \
diff --git a/external/bsd/mdocml/lib/libmandoc/Makefile b/external/bsd/mdocml/lib/libmandoc/Makefile
index 40d7e29ae88..dfd3077a2c7 100644
--- a/external/bsd/mdocml/lib/libmandoc/Makefile
+++ b/external/bsd/mdocml/lib/libmandoc/Makefile
@@ -39,11 +39,6 @@ tbl_opts.c

MAN= mandoc.3

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.mdoc_macro.c+=-O0
-.endif
-
COPTS.man_validate.c+=-Wno-error=array-bounds

.include <bsd.lib.mk>
diff --git a/external/gpl3/binutils.old/lib/libbfd/Makefile b/external/gpl3/binutils.old/lib/libbfd/Makefile
index 03477232b55..74a354532fa 100644
--- a/external/gpl3/binutils.old/lib/libbfd/Makefile
+++ b/external/gpl3/binutils.old/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/binutils/lib/libbfd/Makefile b/external/gpl3/binutils/lib/libbfd/Makefile
index 00cb2b20081..a3f0c25fd35 100644
--- a/external/gpl3/binutils/lib/libbfd/Makefile
+++ b/external/gpl3/binutils/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/gcc.old/lib/Makefile.sanitizer b/external/gpl3/gcc.old/lib/Makefile.sanitizer
index efd36ae4bee..5173a5109a0 100644
--- a/external/gpl3/gcc.old/lib/Makefile.sanitizer
+++ b/external/gpl3/gcc.old/lib/Makefile.sanitizer
@@ -88,22 +88,3 @@ COPTS+=-fno-builtin -fno-exceptions -fno-rtti -funwind-tables

# Can't profile without it`
#-fomit-frame-pointer
-
-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_allocator.cc += -O1
-COPTS.sanitizer_common.cc += -O1
-COPTS.sanitizer_common_libcdep.cc += -O1
-COPTS.sanitizer_coverage_libcdep.cc += -O1
-COPTS.sanitizer_coverage_mapping_libcdep.cc += -O1
-COPTS.sanitizer_deadlock_detector1.cc += -O1
-COPTS.sanitizer_mac.cc += -O1
-COPTS.sanitizer_netbsd.cc += -O1
-COPTS.sanitizer_posix.cc += -O1
-COPTS.sanitizer_printf.cc += -O1
-COPTS.sanitizer_procmaps_common.cc += -O1
-COPTS.sanitizer_stackdepot.cc += -O1
-COPTS.sanitizer_symbolizer_libcdep.cc += -O1
-COPTS.sanitizer_symbolizer_report.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
diff --git a/external/gpl3/gcc.old/lib/libasan/Makefile b/external/gpl3/gcc.old/lib/libasan/Makefile
index 1e6f9608abe..3da7bbf2f58 100644
--- a/external/gpl3/gcc.old/lib/libasan/Makefile
+++ b/external/gpl3/gcc.old/lib/libasan/Makefile
@@ -49,14 +49,6 @@ LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
LIBDPLIBS+= pthread ${NETBSDSRCDIR}/lib/libpthread
CPPFLAGS+=-DCAN_SANITIZE_UB=0

-.if ${MACHINE_ARCH} == "vax"
-COPTS.asan_allocator.cc += -O1
-COPTS.asan_report.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
-
.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
COPTS.asan_interceptors.cc += -O1
.endif
diff --git a/external/gpl3/gcc.old/lib/liblsan/Makefile b/external/gpl3/gcc.old/lib/liblsan/Makefile
index 4578544a9a8..ddb7981077c 100644
--- a/external/gpl3/gcc.old/lib/liblsan/Makefile
+++ b/external/gpl3/gcc.old/lib/liblsan/Makefile
@@ -16,11 +16,6 @@ LSAN_SRCS+= \
lsan_linux.cc \
lsan_thread.cc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lsan_allocator.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= lsan
SRCS+= ${LSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/lib/libubsan/Makefile b/external/gpl3/gcc.old/lib/libubsan/Makefile
index 2e2faca7b1c..9de82550d14 100644
--- a/external/gpl3/gcc.old/lib/libubsan/Makefile
+++ b/external/gpl3/gcc.old/lib/libubsan/Makefile
@@ -26,10 +26,6 @@ UBSAN_SRCS= \
COPTS.${_s}.cc+=-frtti
.endfor

-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= ubsan
SRCS+= ${UBSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/usr.bin/cc1/Makefile b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
index c55e292ee8e..ff12a5be524 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
@@ -46,17 +46,6 @@ CPPFLAGS.default-c.c+= -I${BACKENDOBJ}
BUILDSYMLINKS+= ${GNUHOSTDIST}/gcc/config/sh/sh-c.cc sh-c.c
.endif

-.if ${MACHINE_CPU} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
index 3123ee0d60b..aab82ad3448 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
@@ -44,16 +44,8 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-.endif
+COPTS.c-cppbuiltin.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}
+COPTS.c-typeck.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}

.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
diff --git a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
index b9c108251c5..e04e8fc7f53 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
@@ -69,18 +69,6 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-COPTS.decl.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
index 7936efd3a5e..7c54559e21a 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
@@ -31,23 +31,6 @@ CHECKSUM_OBJS= ${LIBBACKTRACEOBJ}/libbacktrace.a \

CFLAGS+= -Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.call.c+=-O0
-COPTS.decl.c+=-O0
-COPTS.typeck2.c+=-O0
-COPTS.class.c+=-O0
-COPTS.typeck.c+=-O0
-COPTS.init.c+=-O0
-COPTS.semantics.c+=-O0
-COPTS.mangle.c+=-O0
-COPTS.constexpr.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1plus-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/gcc/Makefile b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
index 7a66d77ffc7..a5a4b1c3adf 100644
--- a/external/gpl3/gcc.old/usr.bin/gcc/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
@@ -25,9 +25,6 @@ ${SRCS}: ${GCCARCH}/defs.mk
.include <bsd.info.mk>

COPTS.gcc.c= -Wno-stack-protector
-.if ${MACHINE_ARCH} == "vax"
-COPTS.dse.c= -O1
-.endif

.PATH: ${DIST}/gcc ${DIST}/gcc/doc ${DIST}/gcc/c

diff --git a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
index 751d1513eec..33aeb1c9898 100644
--- a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
@@ -14,10 +14,6 @@ SRCS= decNumber.c decContext.c decimal32.c decimal64.c decimal128.c
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH} -I${DIST}/libdecnumber
CPPFLAGS+= -I${DIST}/libgcc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.include <bsd.lib.mk>

# Force using C++ for this
diff --git a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
index 90f44a9fcf6..fd251464fb7 100644
--- a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
@@ -24,11 +24,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.backtrace"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
DPADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} ${LIBINTL} ${LIBZ} ${LIBM}

diff --git a/external/gpl3/gcc.old/usr.bin/lto1/Makefile b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
index 4c49161a64c..340d3c6124f 100644
--- a/external/gpl3/gcc.old/usr.bin/lto1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
@@ -21,11 +21,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.libcpp"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTYOBJ}/libiberty.a
DPADD+= ${LIBIBERTYOBJ}/libiberty.a
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
diff --git a/external/gpl3/gdb.old/lib/libdecnumber/Makefile b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
index bcd4ae5b222..ce28811526b 100644
--- a/external/gpl3/gdb.old/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libdecnumber/Makefile b/external/gpl3/gdb/lib/libdecnumber/Makefile
index c95d36e3dfa..e3169865304 100644
--- a/external/gpl3/gdb/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd ${DIST}/libdecnumber/bid

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libgdb/Makefile b/external/gpl3/gdb/lib/libgdb/Makefile
index b87a515d13a..c118c363975 100644
--- a/external/gpl3/gdb/lib/libgdb/Makefile
+++ b/external/gpl3/gdb/lib/libgdb/Makefile
@@ -66,12 +66,6 @@ CFLAGS:= ${CXXFLAGS} -std=gnu++17 -Wno-error=stack-protector

ada-exp.c: ada-lex.c

-.if ${MACHINE} == "vax"
-. if ${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8
-COPTS.read.c+= -O0
-. endif
-.endif
-
# These are generated by implicit rules and are not easy to generate
CLEANDIRFILES+= \
ada-exp.c ada-lex.c \
diff --git a/external/mit/xorg/lib/gallium.old/Makefile b/external/mit/xorg/lib/gallium.old/Makefile
index 55b2fe3d1c1..bfa40c8974f 100644
--- a/external/mit/xorg/lib/gallium.old/Makefile
+++ b/external/mit/xorg/lib/gallium.old/Makefile
@@ -1211,10 +1211,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
# XXXGCC12
.if ${MACHINE_ARCH} == "m68k"
COPTS.st_glsl_to_tgsi.cpp += -O1
diff --git a/external/mit/xorg/lib/gallium/Makefile b/external/mit/xorg/lib/gallium/Makefile
index 6778a8c11c8..9f1422080fe 100644
--- a/external/mit/xorg/lib/gallium/Makefile
+++ b/external/mit/xorg/lib/gallium/Makefile
@@ -1428,10 +1428,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
COPTS.u_atomic.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-builtin-declaration-mismatch :}

.include <bsd.lib.mk>
diff --git a/external/mit/xorg/lib/libX11/Makefile.libx11 b/external/mit/xorg/lib/libX11/Makefile.libx11
index e103d9ace12..0e55c2a4732 100644
--- a/external/mit/xorg/lib/libX11/Makefile.libx11
+++ b/external/mit/xorg/lib/libX11/Makefile.libx11
@@ -471,11 +471,6 @@ COPTS.OpenDis.c+= -Wno-error # XXX xf86bigfstr.h
COPTS.XlibInt.c+= -Wno-error # XXX xcmiscstr.h
COPTS.XKBBind.c+= -Wno-deprecated-declarations # uses XKeycodeToKeysym

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.lcWrap.c+= -O0
-.endif
-
CWARNFLAGS.clang+= -Wno-string-plus-int

.include "${NETBSDSRCDIR}/external/mit/xorg/tools/makekeys/Makefile.makekeys"
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile
index e86a63aaea7..678537066ed 100644
--- a/games/gomoku/Makefile
+++ b/games/gomoku/Makefile
@@ -9,10 +9,6 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}

-.if ${MACHINE} == "vax"
-COPTS.pickmove.c += -O0
-.endif
-
#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index e9c53f23ae5..b919dac17c6 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -52,7 +52,3 @@ map: map.c
./map | plot > /dev/tty

.include <bsd.prog.mk>
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/i18n_module/UTF7/Makefile b/lib/i18n_module/UTF7/Makefile
index 712c1515d42..7136f7f0cc3 100644
--- a/lib/i18n_module/UTF7/Makefile
+++ b/lib/i18n_module/UTF7/Makefile
@@ -3,6 +3,3 @@
SRCPRE=citrus_
.include <bsd.lib.mk>

-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.citrus_utf7.c+= -O0
-.endif
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b2aea1e04b0..e60a2862d48 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -15,11 +15,6 @@ SRCS= blocksort.c huffman.c crctable.c randtable.c compress.c \
INCS= bzlib.h
INCSDIR= /usr/include

-# XXX huffman.c gets mis-compiled with 2.95.3
-.if ${MACHINE_ARCH} == "vax"
-COPTS+= -O0
-.endif
-
COPTS+= ${CC_WNO_IMPLICIT_FALLTHROUGH}

# XXX blocksort.c gets mis-compiled with 4.1
diff --git a/lib/libc/gdtoa/Makefile.inc b/lib/libc/gdtoa/Makefile.inc
index 132686fc33d..609da919803 100644
--- a/lib/libc/gdtoa/Makefile.inc
+++ b/lib/libc/gdtoa/Makefile.inc
@@ -44,10 +44,3 @@ SRCS+= dmisc.c \
.if ${MACHINE_ARCH} != "vax"
SRCS+= strtord.c
.endif
-
-# XXX revisit with newer GCC.
-# Ensure numbers like 0xffff319f5fa95963 print correctly
-# ("999999999999999.98", not garbage like "?A>C>@>C:BA;A><.:<")
-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index cb3f89d6d09..e9c8be820da 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -30,9 +30,6 @@ SRCS+= crypt-argon2.c
SRCS+= ${src}
COPTS.${src}+= -fvisibility=hidden
. endfor
-. if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-. endif
.endif

WARNS?= 5
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
index f5baae1e883..24f7e1121e5 100644
--- a/libexec/ld.elf_so/Makefile
+++ b/libexec/ld.elf_so/Makefile
@@ -141,10 +141,6 @@ CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector

-.if ${MACHINE_CPU} == "vax"
-COPTS.rtld.c+= -O0
-.endif
-
LDADD+= -Wl,--version-script=${.CURDIR}/symbols.map
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
diff --git a/sbin/fsck_ffs/Makefile.common b/sbin/fsck_ffs/Makefile.common
index 765638b2801..824e3bf2628 100644
--- a/sbin/fsck_ffs/Makefile.common
+++ b/sbin/fsck_ffs/Makefile.common
@@ -36,7 +36,3 @@ COPTS.ffs_appleufs.c+= -Wno-pointer-sign
.if ${MACHINE_ARCH} == "m68000"
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif
-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-.endif
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index c039f73a1eb..3b0331e5880 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -39,12 +39,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-COPTS.fsdb.c+= -O0
-.endif
-
CWARNFLAGS.gcc+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

.include <bsd.prog.mk>
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 40a44b9a038..ecfdbff4d3a 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -20,8 +20,4 @@ DPADD+=${LIBPROP}

.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mke2fs.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 4f33501ea7a..1f7f56e3ea5 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -12,8 +12,4 @@ CPPFLAGS+= -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax
index cf095d54a86..c483eaa644a 100644
--- a/sys/arch/vax/conf/Makefile.vax
+++ b/sys/arch/vax/conf/Makefile.vax
@@ -34,7 +34,6 @@ GENASSYM_CONF= ${VAX}/vax/genassym.cf
CPPFLAGS+= -D_VAX_INLINE_
AFLAGS+= -x assembler-with-cpp -fno-pic
CFLAGS+= -fno-pic
-COPTS.wsmux.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -O1 :}


##
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 718c97ce857..4ef3840c753 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -96,7 +96,3 @@ SRCS+= ufs.c
lib${LIB}.o:: ${OBJS:O} __buildstdlib

CPPFLAGS+= -Wno-pointer-sign
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.bootp.c+= -O0
-.endif
diff --git a/sys/lib/libz/Makefile b/sys/lib/libz/Makefile
index 6945c0da6c6..61fb7d4f652 100644
--- a/sys/lib/libz/Makefile
+++ b/sys/lib/libz/Makefile
@@ -25,7 +25,3 @@ CLEANFILES+= lib${LIB}.o
.include <bsd.lib.mk>

lib${LIB}.o:: ${OBJS:O} __buildstdlib
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.inftrees.c+= -O0
-.endif
diff --git a/sys/modules/lfs/Makefile b/sys/modules/lfs/Makefile
index 962538821a5..ea8f187e160 100644
--- a/sys/modules/lfs/Makefile
+++ b/sys/modules/lfs/Makefile
@@ -18,9 +18,4 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_inode.c ulfs_lookup.c \

WARNS= 3

-.if ${MACHINE} == "vax"
-# GCC 6.5 and 7.4 cannot compile this with -DDIAGNOSTIC and -O2/-O1
-COPTS.lfs_inode.c+= -O0
-.endif
-
.include <bsd.kmodule.mk>
diff --git a/sys/rump/fs/lib/liblfs/Makefile b/sys/rump/fs/lib/liblfs/Makefile
index abade3767d9..68b74c62502 100644
--- a/sys/rump/fs/lib/liblfs/Makefile
+++ b/sys/rump/fs/lib/liblfs/Makefile
@@ -17,9 +17,6 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_extattr.c \


CFLAGS+= -DLFS_KERNEL_RFW
-.if ${MACHINE_ARCH} == "vax"
-COPTS.lfs_inode.c+=-O0
-.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff --git a/usr.sbin/mtrace/Makefile b/usr.sbin/mtrace/Makefile
index aef09db6198..9c125c15265 100644
--- a/usr.sbin/mtrace/Makefile
+++ b/usr.sbin/mtrace/Makefile
@@ -12,10 +12,6 @@ PROG= mtrace
SRCS= igmp.c inet.c kern.c mtrace.c
MAN= mtrace.8

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mtrace.c=-O0
-.endif
-
BINMODE=4555
BINOWN= root

diff --git a/external/gpl3/gcc.old/usr.bin/backend/Makefile b/external/gpl3/gcc.old/usr.bin/backend/Makefile
index d69a26fe619..99e881c783d 100644
--- a/external/gpl3/gcc.old/usr.bin/backend/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/backend/Makefile
@@ -533,68 +533,9 @@ COPTS.insn-recog.c+=-Wno-error

.if ${GCC_MACHINE_ARCH} == "vax"
CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
-COPTS.builtins.c+=-O0
-COPTS.calls.c+=-O0
-COPTS.convert.c+=-O0
-COPTS.data-streamer-out.c+=-O0
-COPTS.dse.c+=-O0 # XXX port-vax/51967
-COPTS.dwarf2out.c+=-O0
-COPTS.expmed.c+=-O0
-COPTS.expr.c+=-O0 -Wno-error=tautological-compare
-COPTS.fixed-value.c+=-O0
-COPTS.fold-const.c+=-O0
-COPTS.generic-match.c+=-O0
-COPTS.gimple-fold.c+=-O0
-COPTS.gimple-match.c+=-O0
-COPTS.gimple-ssa-strength-reduction.c+=-O0
-COPTS.gimple-ssa-warn-restrict.c+=-O0
-COPTS.gimple.c+=-O0
-COPTS.internal-fn.c+=-O0
-COPTS.lto-streamer-out.c+=-O0
-COPTS.omp-low.c+=-O0
-COPTS.predict.c+=-O0
-COPTS.range-op.cc+=-O0
-COPTS.recog.c+=-O0
-COPTS.sanopt.c+=-O0
-COPTS.stmt.c+=-O0
-COPTS.stor-layout.c+=-O0
-COPTS.targhooks.c+=-O0
-COPTS.tree-affine.c+=-O0
-COPTS.tree-cfg.c+=-O0
-COPTS.tree-data-ref.c+=-O0
-COPTS.tree-eh.c+=-O0
-COPTS.tree-if-conv.c+=-O0
-COPTS.tree-object-size.c+=-O0
-COPTS.tree-parloops.c+=-O0
-COPTS.tree-predcom.c+=-O0
-COPTS.tree-pretty-print.c+=-O0
-COPTS.tree-ssa-alias.c+=-O0
-COPTS.tree-ssa-ccp.c+=-O0
-COPTS.tree-ssa-forwprop.c+=-O0
-COPTS.tree-ssa-loop-ivopts.c+=-O0
-COPTS.tree-ssa-loop-manip.c+=-O0
-COPTS.tree-ssa-loop-niter.c+=-O0
-COPTS.tree-ssa-math-opts.c+=-O0
-COPTS.tree-ssa-phiopt.c+= -O0
-COPTS.tree-ssa-pre.c+=-O0
-COPTS.tree-ssa-reassoc.c+=-O0
-COPTS.tree-ssa-strlen.c+=-O0
-COPTS.tree-ssa-uninit.c+=-O0
-COPTS.tree-ssa.c+=-O0
-COPTS.tree-switch-conversion.c+=-O0
-COPTS.tree-vect-data-refs.c+=-O0
-COPTS.tree-vect-loop-manip.c+=-O0
-COPTS.tree-vect-loop.c+=-O0
-COPTS.tree-vect-patterns.c+=-O0
-COPTS.tree-vect-stmts.c+=-O0
-COPTS.tree-vrp.c+=-O0
-COPTS.tree.c+=-O0
-COPTS.ubsan.c+=-O0
-COPTS.varasm.c+=-O0
-COPTS.vr-values.c+=-O0
-COPTS.web.c+=-O0
-COPTS.wide-int-range.cc+=-O0
-COPTS.wide-int.cc+=-O0
+
+COPTS.expmed.c+=-Wno-error=tautological-compare
+COPTS.expr.c+=-Wno-error=tautological-compare
.else
COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
.endif


# 1.147 30-Jul-2023 riastradh

ld.elf_so: Split hash functions into a separate file.

This way we can test them in isolation.

No functional change intended.


# 1.146 30-Jul-2023 riastradh

ld.elf_so: Sort SRCS.

No functional change intended.


# 1.145 30-Jul-2023 riastradh

ld.elf_so: Split SRCS onto multiple lines.

Makes updates easier.

No functional change intended.


Revision tags: netbsd-10-base
# 1.144 04-Dec-2021 skrll

branches: 1.144.2;
Error if there are undefined symbols, e.g. _rtld_call_ifunc


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.143 09-Feb-2020 kamil

Specify NOLIBCSANITIZER for the ELF loader

The sanitizer does not work reliably before finishing initialization of
ld.elf_so. There is also a number of false positives that are not real
problems here.


Revision tags: phil-wifi-20191119
# 1.142 04-Nov-2019 joerg

PR 54093: Align static TLS area to max_align_t.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.141 03-Apr-2019 christos

branches: 1.141.2;
Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

branches: 1.138.2;
We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.148 07-Oct-2023 rin

Drop -O[01] hacks for vax; no longer necessary for patched GCC 10

PR port-vax/57646: Import major vax toolchain fix by Kalvis Duckmanton

XXXRO: GCC 12 may require hacks for a while, but it turned out that
GCC 12 should be treated differently from older versions; a lot of new
files need -O[01] flags, while some may no longer require it.

I will take a look later.

Note that these hacks are not required if Kalvis's patches for GCC 12
are applied.

Keep doc/HACKS entries for a while (will be sync with update for GCC 12).

diff --git a/crypto/external/bsd/openssh/lib/Makefile b/crypto/external/bsd/openssh/lib/Makefile
index 96a93f5e396..4e38be1b642 100644
--- a/crypto/external/bsd/openssh/lib/Makefile
+++ b/crypto/external/bsd/openssh/lib/Makefile
@@ -117,12 +117,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
# XXX
COPTS.channels.c+= -fno-strict-aliasing

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.poly1305.c+= -O0
-COPTS.umac.c+= -O0
-.endif
-
COPTS.hostfile.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.sshkey.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.cipher.c+= -Wno-error=deprecated-declarations
diff --git a/distrib/utils/x_ping/Makefile b/distrib/utils/x_ping/Makefile
index f1c452a0d60..8ee77580a3f 100644
--- a/distrib/utils/x_ping/Makefile
+++ b/distrib/utils/x_ping/Makefile
@@ -12,10 +12,6 @@ CPPFLAGS+= -I${SRCDIR} -DCRUNCHOPS
DPADD= ${LIBM}
LDADD= -lm

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>

.PATH: ${SRCDIR}
diff --git a/external/apache2/argon2/lib/libargon2/Makefile.inc b/external/apache2/argon2/lib/libargon2/Makefile.inc
index d3f4470c6c7..6a1dd146d7d 100644
--- a/external/apache2/argon2/lib/libargon2/Makefile.inc
+++ b/external/apache2/argon2/lib/libargon2/Makefile.inc
@@ -16,7 +16,3 @@ CFLAGS+= -pthread
LDADD+=-lpthread
DPADD+=${LIBPTHREAD}
.endif
-
-.if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-.endif
diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc
index 2f524358f46..d5da774f293 100644
--- a/external/bsd/jemalloc/lib/Makefile.inc
+++ b/external/bsd/jemalloc/lib/Makefile.inc
@@ -53,12 +53,6 @@ COPTS.ctl.c+=-Wno-error=stack-protector
COPTS.stats.c+=-Wno-error=stack-protector
COPTS.tcache.c+=-Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-# in merge_overlapping_regs, at regrename.c
-COPTS.arena.c+=-O0
-COPTS.extent.c+=-O0
-.endif
-
SRCS+=${JEMALLOC_SRCS}

jemalloc.d jemalloc.pico jemalloc.o jemalloc.ln jemalloc.po jemalloc.go: \
diff --git a/external/bsd/mdocml/lib/libmandoc/Makefile b/external/bsd/mdocml/lib/libmandoc/Makefile
index 40d7e29ae88..dfd3077a2c7 100644
--- a/external/bsd/mdocml/lib/libmandoc/Makefile
+++ b/external/bsd/mdocml/lib/libmandoc/Makefile
@@ -39,11 +39,6 @@ tbl_opts.c

MAN= mandoc.3

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.mdoc_macro.c+=-O0
-.endif
-
COPTS.man_validate.c+=-Wno-error=array-bounds

.include <bsd.lib.mk>
diff --git a/external/gpl3/binutils.old/lib/libbfd/Makefile b/external/gpl3/binutils.old/lib/libbfd/Makefile
index 03477232b55..74a354532fa 100644
--- a/external/gpl3/binutils.old/lib/libbfd/Makefile
+++ b/external/gpl3/binutils.old/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/binutils/lib/libbfd/Makefile b/external/gpl3/binutils/lib/libbfd/Makefile
index 00cb2b20081..a3f0c25fd35 100644
--- a/external/gpl3/binutils/lib/libbfd/Makefile
+++ b/external/gpl3/binutils/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/gcc.old/lib/Makefile.sanitizer b/external/gpl3/gcc.old/lib/Makefile.sanitizer
index efd36ae4bee..5173a5109a0 100644
--- a/external/gpl3/gcc.old/lib/Makefile.sanitizer
+++ b/external/gpl3/gcc.old/lib/Makefile.sanitizer
@@ -88,22 +88,3 @@ COPTS+=-fno-builtin -fno-exceptions -fno-rtti -funwind-tables

# Can't profile without it`
#-fomit-frame-pointer
-
-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_allocator.cc += -O1
-COPTS.sanitizer_common.cc += -O1
-COPTS.sanitizer_common_libcdep.cc += -O1
-COPTS.sanitizer_coverage_libcdep.cc += -O1
-COPTS.sanitizer_coverage_mapping_libcdep.cc += -O1
-COPTS.sanitizer_deadlock_detector1.cc += -O1
-COPTS.sanitizer_mac.cc += -O1
-COPTS.sanitizer_netbsd.cc += -O1
-COPTS.sanitizer_posix.cc += -O1
-COPTS.sanitizer_printf.cc += -O1
-COPTS.sanitizer_procmaps_common.cc += -O1
-COPTS.sanitizer_stackdepot.cc += -O1
-COPTS.sanitizer_symbolizer_libcdep.cc += -O1
-COPTS.sanitizer_symbolizer_report.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
diff --git a/external/gpl3/gcc.old/lib/libasan/Makefile b/external/gpl3/gcc.old/lib/libasan/Makefile
index 1e6f9608abe..3da7bbf2f58 100644
--- a/external/gpl3/gcc.old/lib/libasan/Makefile
+++ b/external/gpl3/gcc.old/lib/libasan/Makefile
@@ -49,14 +49,6 @@ LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
LIBDPLIBS+= pthread ${NETBSDSRCDIR}/lib/libpthread
CPPFLAGS+=-DCAN_SANITIZE_UB=0

-.if ${MACHINE_ARCH} == "vax"
-COPTS.asan_allocator.cc += -O1
-COPTS.asan_report.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
-
.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
COPTS.asan_interceptors.cc += -O1
.endif
diff --git a/external/gpl3/gcc.old/lib/liblsan/Makefile b/external/gpl3/gcc.old/lib/liblsan/Makefile
index 4578544a9a8..ddb7981077c 100644
--- a/external/gpl3/gcc.old/lib/liblsan/Makefile
+++ b/external/gpl3/gcc.old/lib/liblsan/Makefile
@@ -16,11 +16,6 @@ LSAN_SRCS+= \
lsan_linux.cc \
lsan_thread.cc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lsan_allocator.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= lsan
SRCS+= ${LSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/lib/libubsan/Makefile b/external/gpl3/gcc.old/lib/libubsan/Makefile
index 2e2faca7b1c..9de82550d14 100644
--- a/external/gpl3/gcc.old/lib/libubsan/Makefile
+++ b/external/gpl3/gcc.old/lib/libubsan/Makefile
@@ -26,10 +26,6 @@ UBSAN_SRCS= \
COPTS.${_s}.cc+=-frtti
.endfor

-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= ubsan
SRCS+= ${UBSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/usr.bin/cc1/Makefile b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
index c55e292ee8e..ff12a5be524 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
@@ -46,17 +46,6 @@ CPPFLAGS.default-c.c+= -I${BACKENDOBJ}
BUILDSYMLINKS+= ${GNUHOSTDIST}/gcc/config/sh/sh-c.cc sh-c.c
.endif

-.if ${MACHINE_CPU} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
index 3123ee0d60b..aab82ad3448 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
@@ -44,16 +44,8 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-.endif
+COPTS.c-cppbuiltin.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}
+COPTS.c-typeck.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}

.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
diff --git a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
index b9c108251c5..e04e8fc7f53 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
@@ -69,18 +69,6 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-COPTS.decl.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
index 7936efd3a5e..7c54559e21a 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
@@ -31,23 +31,6 @@ CHECKSUM_OBJS= ${LIBBACKTRACEOBJ}/libbacktrace.a \

CFLAGS+= -Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.call.c+=-O0
-COPTS.decl.c+=-O0
-COPTS.typeck2.c+=-O0
-COPTS.class.c+=-O0
-COPTS.typeck.c+=-O0
-COPTS.init.c+=-O0
-COPTS.semantics.c+=-O0
-COPTS.mangle.c+=-O0
-COPTS.constexpr.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1plus-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/gcc/Makefile b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
index 7a66d77ffc7..a5a4b1c3adf 100644
--- a/external/gpl3/gcc.old/usr.bin/gcc/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
@@ -25,9 +25,6 @@ ${SRCS}: ${GCCARCH}/defs.mk
.include <bsd.info.mk>

COPTS.gcc.c= -Wno-stack-protector
-.if ${MACHINE_ARCH} == "vax"
-COPTS.dse.c= -O1
-.endif

.PATH: ${DIST}/gcc ${DIST}/gcc/doc ${DIST}/gcc/c

diff --git a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
index 751d1513eec..33aeb1c9898 100644
--- a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
@@ -14,10 +14,6 @@ SRCS= decNumber.c decContext.c decimal32.c decimal64.c decimal128.c
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH} -I${DIST}/libdecnumber
CPPFLAGS+= -I${DIST}/libgcc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.include <bsd.lib.mk>

# Force using C++ for this
diff --git a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
index 90f44a9fcf6..fd251464fb7 100644
--- a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
@@ -24,11 +24,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.backtrace"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
DPADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} ${LIBINTL} ${LIBZ} ${LIBM}

diff --git a/external/gpl3/gcc.old/usr.bin/lto1/Makefile b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
index 4c49161a64c..340d3c6124f 100644
--- a/external/gpl3/gcc.old/usr.bin/lto1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
@@ -21,11 +21,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.libcpp"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTYOBJ}/libiberty.a
DPADD+= ${LIBIBERTYOBJ}/libiberty.a
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
diff --git a/external/gpl3/gdb.old/lib/libdecnumber/Makefile b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
index bcd4ae5b222..ce28811526b 100644
--- a/external/gpl3/gdb.old/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libdecnumber/Makefile b/external/gpl3/gdb/lib/libdecnumber/Makefile
index c95d36e3dfa..e3169865304 100644
--- a/external/gpl3/gdb/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd ${DIST}/libdecnumber/bid

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libgdb/Makefile b/external/gpl3/gdb/lib/libgdb/Makefile
index b87a515d13a..c118c363975 100644
--- a/external/gpl3/gdb/lib/libgdb/Makefile
+++ b/external/gpl3/gdb/lib/libgdb/Makefile
@@ -66,12 +66,6 @@ CFLAGS:= ${CXXFLAGS} -std=gnu++17 -Wno-error=stack-protector

ada-exp.c: ada-lex.c

-.if ${MACHINE} == "vax"
-. if ${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8
-COPTS.read.c+= -O0
-. endif
-.endif
-
# These are generated by implicit rules and are not easy to generate
CLEANDIRFILES+= \
ada-exp.c ada-lex.c \
diff --git a/external/mit/xorg/lib/gallium.old/Makefile b/external/mit/xorg/lib/gallium.old/Makefile
index 55b2fe3d1c1..bfa40c8974f 100644
--- a/external/mit/xorg/lib/gallium.old/Makefile
+++ b/external/mit/xorg/lib/gallium.old/Makefile
@@ -1211,10 +1211,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
# XXXGCC12
.if ${MACHINE_ARCH} == "m68k"
COPTS.st_glsl_to_tgsi.cpp += -O1
diff --git a/external/mit/xorg/lib/gallium/Makefile b/external/mit/xorg/lib/gallium/Makefile
index 6778a8c11c8..9f1422080fe 100644
--- a/external/mit/xorg/lib/gallium/Makefile
+++ b/external/mit/xorg/lib/gallium/Makefile
@@ -1428,10 +1428,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
COPTS.u_atomic.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-builtin-declaration-mismatch :}

.include <bsd.lib.mk>
diff --git a/external/mit/xorg/lib/libX11/Makefile.libx11 b/external/mit/xorg/lib/libX11/Makefile.libx11
index e103d9ace12..0e55c2a4732 100644
--- a/external/mit/xorg/lib/libX11/Makefile.libx11
+++ b/external/mit/xorg/lib/libX11/Makefile.libx11
@@ -471,11 +471,6 @@ COPTS.OpenDis.c+= -Wno-error # XXX xf86bigfstr.h
COPTS.XlibInt.c+= -Wno-error # XXX xcmiscstr.h
COPTS.XKBBind.c+= -Wno-deprecated-declarations # uses XKeycodeToKeysym

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.lcWrap.c+= -O0
-.endif
-
CWARNFLAGS.clang+= -Wno-string-plus-int

.include "${NETBSDSRCDIR}/external/mit/xorg/tools/makekeys/Makefile.makekeys"
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile
index e86a63aaea7..678537066ed 100644
--- a/games/gomoku/Makefile
+++ b/games/gomoku/Makefile
@@ -9,10 +9,6 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}

-.if ${MACHINE} == "vax"
-COPTS.pickmove.c += -O0
-.endif
-
#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index e9c53f23ae5..b919dac17c6 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -52,7 +52,3 @@ map: map.c
./map | plot > /dev/tty

.include <bsd.prog.mk>
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/i18n_module/UTF7/Makefile b/lib/i18n_module/UTF7/Makefile
index 712c1515d42..7136f7f0cc3 100644
--- a/lib/i18n_module/UTF7/Makefile
+++ b/lib/i18n_module/UTF7/Makefile
@@ -3,6 +3,3 @@
SRCPRE=citrus_
.include <bsd.lib.mk>

-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.citrus_utf7.c+= -O0
-.endif
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b2aea1e04b0..e60a2862d48 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -15,11 +15,6 @@ SRCS= blocksort.c huffman.c crctable.c randtable.c compress.c \
INCS= bzlib.h
INCSDIR= /usr/include

-# XXX huffman.c gets mis-compiled with 2.95.3
-.if ${MACHINE_ARCH} == "vax"
-COPTS+= -O0
-.endif
-
COPTS+= ${CC_WNO_IMPLICIT_FALLTHROUGH}

# XXX blocksort.c gets mis-compiled with 4.1
diff --git a/lib/libc/gdtoa/Makefile.inc b/lib/libc/gdtoa/Makefile.inc
index 132686fc33d..609da919803 100644
--- a/lib/libc/gdtoa/Makefile.inc
+++ b/lib/libc/gdtoa/Makefile.inc
@@ -44,10 +44,3 @@ SRCS+= dmisc.c \
.if ${MACHINE_ARCH} != "vax"
SRCS+= strtord.c
.endif
-
-# XXX revisit with newer GCC.
-# Ensure numbers like 0xffff319f5fa95963 print correctly
-# ("999999999999999.98", not garbage like "?A>C>@>C:BA;A><.:<")
-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index cb3f89d6d09..e9c8be820da 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -30,9 +30,6 @@ SRCS+= crypt-argon2.c
SRCS+= ${src}
COPTS.${src}+= -fvisibility=hidden
. endfor
-. if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-. endif
.endif

WARNS?= 5
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
index f5baae1e883..24f7e1121e5 100644
--- a/libexec/ld.elf_so/Makefile
+++ b/libexec/ld.elf_so/Makefile
@@ -141,10 +141,6 @@ CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector

-.if ${MACHINE_CPU} == "vax"
-COPTS.rtld.c+= -O0
-.endif
-
LDADD+= -Wl,--version-script=${.CURDIR}/symbols.map
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
diff --git a/sbin/fsck_ffs/Makefile.common b/sbin/fsck_ffs/Makefile.common
index 765638b2801..824e3bf2628 100644
--- a/sbin/fsck_ffs/Makefile.common
+++ b/sbin/fsck_ffs/Makefile.common
@@ -36,7 +36,3 @@ COPTS.ffs_appleufs.c+= -Wno-pointer-sign
.if ${MACHINE_ARCH} == "m68000"
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif
-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-.endif
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index c039f73a1eb..3b0331e5880 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -39,12 +39,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-COPTS.fsdb.c+= -O0
-.endif
-
CWARNFLAGS.gcc+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

.include <bsd.prog.mk>
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 40a44b9a038..ecfdbff4d3a 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -20,8 +20,4 @@ DPADD+=${LIBPROP}

.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mke2fs.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 4f33501ea7a..1f7f56e3ea5 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -12,8 +12,4 @@ CPPFLAGS+= -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax
index cf095d54a86..c483eaa644a 100644
--- a/sys/arch/vax/conf/Makefile.vax
+++ b/sys/arch/vax/conf/Makefile.vax
@@ -34,7 +34,6 @@ GENASSYM_CONF= ${VAX}/vax/genassym.cf
CPPFLAGS+= -D_VAX_INLINE_
AFLAGS+= -x assembler-with-cpp -fno-pic
CFLAGS+= -fno-pic
-COPTS.wsmux.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -O1 :}


##
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 718c97ce857..4ef3840c753 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -96,7 +96,3 @@ SRCS+= ufs.c
lib${LIB}.o:: ${OBJS:O} __buildstdlib

CPPFLAGS+= -Wno-pointer-sign
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.bootp.c+= -O0
-.endif
diff --git a/sys/lib/libz/Makefile b/sys/lib/libz/Makefile
index 6945c0da6c6..61fb7d4f652 100644
--- a/sys/lib/libz/Makefile
+++ b/sys/lib/libz/Makefile
@@ -25,7 +25,3 @@ CLEANFILES+= lib${LIB}.o
.include <bsd.lib.mk>

lib${LIB}.o:: ${OBJS:O} __buildstdlib
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.inftrees.c+= -O0
-.endif
diff --git a/sys/modules/lfs/Makefile b/sys/modules/lfs/Makefile
index 962538821a5..ea8f187e160 100644
--- a/sys/modules/lfs/Makefile
+++ b/sys/modules/lfs/Makefile
@@ -18,9 +18,4 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_inode.c ulfs_lookup.c \

WARNS= 3

-.if ${MACHINE} == "vax"
-# GCC 6.5 and 7.4 cannot compile this with -DDIAGNOSTIC and -O2/-O1
-COPTS.lfs_inode.c+= -O0
-.endif
-
.include <bsd.kmodule.mk>
diff --git a/sys/rump/fs/lib/liblfs/Makefile b/sys/rump/fs/lib/liblfs/Makefile
index abade3767d9..68b74c62502 100644
--- a/sys/rump/fs/lib/liblfs/Makefile
+++ b/sys/rump/fs/lib/liblfs/Makefile
@@ -17,9 +17,6 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_extattr.c \


CFLAGS+= -DLFS_KERNEL_RFW
-.if ${MACHINE_ARCH} == "vax"
-COPTS.lfs_inode.c+=-O0
-.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff --git a/usr.sbin/mtrace/Makefile b/usr.sbin/mtrace/Makefile
index aef09db6198..9c125c15265 100644
--- a/usr.sbin/mtrace/Makefile
+++ b/usr.sbin/mtrace/Makefile
@@ -12,10 +12,6 @@ PROG= mtrace
SRCS= igmp.c inet.c kern.c mtrace.c
MAN= mtrace.8

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mtrace.c=-O0
-.endif
-
BINMODE=4555
BINOWN= root

diff --git a/external/gpl3/gcc.old/usr.bin/backend/Makefile b/external/gpl3/gcc.old/usr.bin/backend/Makefile
index d69a26fe619..99e881c783d 100644
--- a/external/gpl3/gcc.old/usr.bin/backend/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/backend/Makefile
@@ -533,68 +533,9 @@ COPTS.insn-recog.c+=-Wno-error

.if ${GCC_MACHINE_ARCH} == "vax"
CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
-COPTS.builtins.c+=-O0
-COPTS.calls.c+=-O0
-COPTS.convert.c+=-O0
-COPTS.data-streamer-out.c+=-O0
-COPTS.dse.c+=-O0 # XXX port-vax/51967
-COPTS.dwarf2out.c+=-O0
-COPTS.expmed.c+=-O0
-COPTS.expr.c+=-O0 -Wno-error=tautological-compare
-COPTS.fixed-value.c+=-O0
-COPTS.fold-const.c+=-O0
-COPTS.generic-match.c+=-O0
-COPTS.gimple-fold.c+=-O0
-COPTS.gimple-match.c+=-O0
-COPTS.gimple-ssa-strength-reduction.c+=-O0
-COPTS.gimple-ssa-warn-restrict.c+=-O0
-COPTS.gimple.c+=-O0
-COPTS.internal-fn.c+=-O0
-COPTS.lto-streamer-out.c+=-O0
-COPTS.omp-low.c+=-O0
-COPTS.predict.c+=-O0
-COPTS.range-op.cc+=-O0
-COPTS.recog.c+=-O0
-COPTS.sanopt.c+=-O0
-COPTS.stmt.c+=-O0
-COPTS.stor-layout.c+=-O0
-COPTS.targhooks.c+=-O0
-COPTS.tree-affine.c+=-O0
-COPTS.tree-cfg.c+=-O0
-COPTS.tree-data-ref.c+=-O0
-COPTS.tree-eh.c+=-O0
-COPTS.tree-if-conv.c+=-O0
-COPTS.tree-object-size.c+=-O0
-COPTS.tree-parloops.c+=-O0
-COPTS.tree-predcom.c+=-O0
-COPTS.tree-pretty-print.c+=-O0
-COPTS.tree-ssa-alias.c+=-O0
-COPTS.tree-ssa-ccp.c+=-O0
-COPTS.tree-ssa-forwprop.c+=-O0
-COPTS.tree-ssa-loop-ivopts.c+=-O0
-COPTS.tree-ssa-loop-manip.c+=-O0
-COPTS.tree-ssa-loop-niter.c+=-O0
-COPTS.tree-ssa-math-opts.c+=-O0
-COPTS.tree-ssa-phiopt.c+= -O0
-COPTS.tree-ssa-pre.c+=-O0
-COPTS.tree-ssa-reassoc.c+=-O0
-COPTS.tree-ssa-strlen.c+=-O0
-COPTS.tree-ssa-uninit.c+=-O0
-COPTS.tree-ssa.c+=-O0
-COPTS.tree-switch-conversion.c+=-O0
-COPTS.tree-vect-data-refs.c+=-O0
-COPTS.tree-vect-loop-manip.c+=-O0
-COPTS.tree-vect-loop.c+=-O0
-COPTS.tree-vect-patterns.c+=-O0
-COPTS.tree-vect-stmts.c+=-O0
-COPTS.tree-vrp.c+=-O0
-COPTS.tree.c+=-O0
-COPTS.ubsan.c+=-O0
-COPTS.varasm.c+=-O0
-COPTS.vr-values.c+=-O0
-COPTS.web.c+=-O0
-COPTS.wide-int-range.cc+=-O0
-COPTS.wide-int.cc+=-O0
+
+COPTS.expmed.c+=-Wno-error=tautological-compare
+COPTS.expr.c+=-Wno-error=tautological-compare
.else
COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
.endif


# 1.147 30-Jul-2023 riastradh

ld.elf_so: Split hash functions into a separate file.

This way we can test them in isolation.

No functional change intended.


# 1.146 30-Jul-2023 riastradh

ld.elf_so: Sort SRCS.

No functional change intended.


# 1.145 30-Jul-2023 riastradh

ld.elf_so: Split SRCS onto multiple lines.

Makes updates easier.

No functional change intended.


Revision tags: netbsd-10-base
# 1.144 04-Dec-2021 skrll

branches: 1.144.2;
Error if there are undefined symbols, e.g. _rtld_call_ifunc


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.143 09-Feb-2020 kamil

Specify NOLIBCSANITIZER for the ELF loader

The sanitizer does not work reliably before finishing initialization of
ld.elf_so. There is also a number of false positives that are not real
problems here.


Revision tags: phil-wifi-20191119
# 1.142 04-Nov-2019 joerg

PR 54093: Align static TLS area to max_align_t.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.141 03-Apr-2019 christos

branches: 1.141.2;
Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

branches: 1.138.2;
We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.147 30-Jul-2023 riastradh

ld.elf_so: Split hash functions into a separate file.

This way we can test them in isolation.

No functional change intended.


# 1.146 30-Jul-2023 riastradh

ld.elf_so: Sort SRCS.

No functional change intended.


# 1.145 30-Jul-2023 riastradh

ld.elf_so: Split SRCS onto multiple lines.

Makes updates easier.

No functional change intended.


Revision tags: netbsd-10-base
# 1.144 04-Dec-2021 skrll

Error if there are undefined symbols, e.g. _rtld_call_ifunc


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.143 09-Feb-2020 kamil

Specify NOLIBCSANITIZER for the ELF loader

The sanitizer does not work reliably before finishing initialization of
ld.elf_so. There is also a number of false positives that are not real
problems here.


Revision tags: phil-wifi-20191119
# 1.142 04-Nov-2019 joerg

PR 54093: Align static TLS area to max_align_t.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.141 03-Apr-2019 christos

branches: 1.141.2;
Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

branches: 1.138.2;
We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.144 04-Dec-2021 skrll

Error if there are undefined symbols, e.g. _rtld_call_ifunc


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.143 09-Feb-2020 kamil

Specify NOLIBCSANITIZER for the ELF loader

The sanitizer does not work reliably before finishing initialization of
ld.elf_so. There is also a number of false positives that are not real
problems here.


Revision tags: phil-wifi-20191119
# 1.142 04-Nov-2019 joerg

PR 54093: Align static TLS area to max_align_t.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.141 03-Apr-2019 christos

branches: 1.141.2;
Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

branches: 1.138.2;
We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.143 09-Feb-2020 kamil

Specify NOLIBCSANITIZER for the ELF loader

The sanitizer does not work reliably before finishing initialization of
ld.elf_so. There is also a number of false positives that are not real
problems here.


Revision tags: phil-wifi-20191119
# 1.142 04-Nov-2019 joerg

PR 54093: Align static TLS area to max_align_t.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.141 03-Apr-2019 christos

branches: 1.141.2;
Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

branches: 1.138.2;
We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.142 04-Nov-2019 joerg

PR 54093: Align static TLS area to max_align_t.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.141 03-Apr-2019 christos

Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

branches: 1.138.2;
We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.141 03-Apr-2019 christos

Disable optimization for rtld.c on the vax with gcc-7.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.140 27-Dec-2018 christos

initfini array support for everyone.


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.139 17-Oct-2018 joerg

Move compatibility for pre-2.0 ELF binaries into separate file.
Early ELF binaries defined dlopen and friends in crt0.o by
using function pointers in the object handle passed from rtld.
This contract wastes space when many shared objects are allocated
and ties dynamic linker and rest of the system tightly together.
Fake the entry points in a static object and restrict them to the
platforms that had working ELF support at the time. Keep the magic and
version field used by modern crt0.o for all architectures. The checks
will be removed from crt0.o in a follow-up step.


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.138 09-Jun-2018 christos

We can't build those three with MKSANITIZER, they are used too early.


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base perseant-stdc-iso10646-base
# 1.137 19-Jun-2017 joerg

branches: 1.137.4;
Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

branches: 1.136.6;
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.137 19-Jun-2017 joerg

Replace COMBREL with just-in-time check in _rtld_relocate_nonplt_objects.

The COMBREL logic predates thread-safety of the dynamic linker and
breaks the use of shared locks for the common symbol lookup case. It is
unlikely to provide any benefit for lazy binding or PLT lookups, so
provide equivalent functionality in the non-PLT relocation handling loop
by checking if the symbol used by the current relocation is the same as
the one used during the last lookup. No inter-object cachine is done as
it is also unlikely to be benefical.

Testing with Firefox startup on AMD64 shows a small performance gain by
the new method.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.136 01-Dec-2016 christos

Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.


# 1.136 01-Dec-2016 christos

Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


Revision tags: pgoyette-localcount-20161104
# 1.135 07-Oct-2016 christos

revert, I'll fix libc instead.


# 1.134 07-Oct-2016 christos

Mips o32 needs -lgcc for __udivdi3 in headers.c for fast_divide32_prepare().


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.133 16-Jun-2016 christos

branches: 1.133.2;
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


# 1.132 15-Jun-2016 christos

Turn off GNU_RELRO for now.


# 1.131 14-Jun-2016 christos

Add support for GNU RELRO headers from Matthias Weckbecker.


# 1.130 23-Jan-2016 christos

Define _KERNTYPES for things that need it.


# 1.129 19-Sep-2014 matt

RISC-V support.


# 1.128 03-Sep-2014 matt

OR1K support


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.127 10-Aug-2014 matt

Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.


Revision tags: yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.126 06-Mar-2014 matt

Enable building ld.elf_so for powerpc
Produce a link map for ld.elf_so


# 1.125 16-Nov-2013 skrll

Remove hack now it's fixed in 4.8.2


# 1.124 13-Nov-2013 skrll

Apply hack for gcc 4.8 bug on rtld.c.


# 1.123 09-Oct-2013 matt

Use MACHINE_CPU for m68k. Use similar logic for both tests.


# 1.122 12-Aug-2013 joerg

Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1
# 1.121 18-Jul-2013 matt

Support MACHINE_ARCH of coldfire


Revision tags: riastradh-drm2-base
# 1.120 09-May-2013 skrll

branches: 1.120.2;
Fix debug symlink


# 1.119 08-May-2013 christos

provide debug symlink.


# 1.118 06-May-2013 christos

don't overwrite COPTS


# 1.117 03-May-2013 matt

Consistently use LDELFSO_MACHINE_ARCH.


# 1.116 24-Apr-2013 matt

Add support for PT_ARM_EXIDX and __gnu_Unwind_Find_exidx for libgcc's support
of the ARM EHABI.


# 1.115 05-Apr-2013 christos

split debug info for rtld


Revision tags: agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.114 23-Aug-2012 joerg

branches: 1.114.2;
Revert last, it breaks the tricks xsrc uses.


# 1.113 23-Aug-2012 joerg

Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.


# 1.112 04-Aug-2012 matt

Don't abuse DBG, use COPTS instead.


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.111 15-Mar-2012 christos

Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.110 07-Oct-2011 mrg

branches: 1.110.2; 1.110.6;
obsolete libgcc_pic and friends. all libgcc's are supposed to be pic
for platforms with shlibs already (and are.)

this obsoletes our hacks for the libgcc specs to use libgcc_pic, and
fixes a couple of other issues reported to me directly.


# 1.109 27-Jun-2011 uwe

sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


# 1.108 25-Jun-2011 nonaka

PR/45015: ld.elf_so: support ELF symbol versioning
Applied latest patch.


# 1.107 05-Jun-2011 christos

Add libgcc_pic for millicode.


Revision tags: cherry-xenmp-base
# 1.106 30-May-2011 joerg

branches: 1.106.2;
Use -Wl,-Bsymbolic directly for clang


# 1.105 20-May-2011 joerg

Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


# 1.104 20-May-2011 joerg

Explicitly disable linking against libgcc and friends.


# 1.103 09-Mar-2011 joerg

Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.102 16-Jan-2011 matt

Warn about DT_TEXTRELs


Revision tags: matt-mips64-premerge-20101231
# 1.101 16-Dec-2010 joerg

Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.


# 1.100 16-Dec-2010 joerg

Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


# 1.99 05-Dec-2010 joerg

Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


# 1.98 29-Oct-2010 christos

PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


# 1.97 06-Jul-2010 mrg

remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h


# 1.96 20-Mar-2010 skrll

Only apply -Wno-stack-protector where alloca is used.


# 1.95 19-Mar-2010 roy

Use the gcc directive to disable SSP warnings.


# 1.94 18-Mar-2010 roy

Use alloca(3) instead of local xmalloc for creating our DoneLists.
This allows threaded programs to use us a little better, PR lib/43005.
We need to disable SSP when using alloca.


Revision tags: matt-premerge-20091211
# 1.93 13-Dec-2009 mrg

simplify the logic for compat ld.elf_so and move it here. we now can
find the libc objdir for multiple compat ld.elf_so's, too.


# 1.92 13-Dec-2009 mrg

if BSD_MK_COMPAT_FILE is defined, .include it.


# 1.91 13-Dec-2009 mrg

rename LD32DIR to MLIBDIR.


# 1.90 20-May-2009 ad

Add a reminder about ldd depending on ld.so.


# 1.89 19-May-2009 christos

warns=4


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.88 16-Mar-2009 lukem

Default to WARNS=4
Exceptions that need a lower level are:
getty ld.elf_so lfs_cleanerd makewhatis telnetd tftpd
hpropd ipropd-master ipropd-slave kadmind kpasswdd


Revision tags: netbsd-5-1-5-RELEASE netbsd-5-1-4-RELEASE netbsd-5-1-3-RELEASE netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base
# 1.87 26-Oct-2008 mrg

branches: 1.87.2; 1.87.4; 1.87.8;
if LD32DIR is defined:
- look in src/compat/lib/libc for libc_pic.
- define RTLD_ARCH_SUBDIR to "i386" or "sparc" for amd64 and sparc64
builds, respectively
if RTLD_ARCH_SUBDIR is defined, add this path before
RTLD_DEFAULT_LIBRARY_PATH in the default search path.


Revision tags: matt-mips64-base2
# 1.86 16-Oct-2008 christos

Never build this with PIE.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.85 26-Dec-2007 christos

No need for stack_protector.o if USE_FORT is no.
XXX: compiling a binary with -Wl,--dynamic-linker,${NETBSDSRCDIR}/libexec/...
results in stack overflow. Investigate!


Revision tags: cube-autoconf-base
# 1.84 13-Nov-2007 ad

stack_protector.c has moved.


# 1.83 30-Oct-2007 skrll

Build a local copy of exit that doesn't call __cxa_finalize. It's not
needed and drags in a lot of libc via free.


# 1.82 29-Oct-2007 christos

build stack protector locally so that we don't call syslog_ss that results
in 1/2 of libc dragged in.


# 1.81 05-Oct-2007 ad

- Don't use the names malloc/free/etc, since we can end up pulling in libc's
malloc which is not what we want.
- Remove ancient memory compaction hack. Realloc on free memory is now an
error again (from joerg@).

Ok christos@.


# 1.80 27-Sep-2007 christos

If we are using SSP, compile in a separate copy of the stack protector
functions so that we don't end up calling syslog_ss() which drags in
a large portion of libc. Found by skrll...


Revision tags: matt-mips64-base
# 1.79 18-May-2007 christos

branches: 1.79.4;
Support Solaris-like $ORIGIN etc. expansions in paths.


# 1.78 08-Apr-2007 scw

Remove support for NetBSD/{,evb}sh5.


# 1.77 15-Mar-2007 matt

Deal with MKPICLIB != no.


# 1.76 23-Feb-2007 matt

Remove MD COMBRELOC support since it's now MI.
Enable COMBRELOC for all arches


Revision tags: netbsd-4-base
# 1.75 27-Aug-2006 simonb

branches: 1.75.2; 1.75.4;
Simplify multiple MACHINE_ARCH endian checks with single MACHINE_CPU
checks.


Revision tags: abandoned-netbsd-4-base
# 1.74 29-Jun-2006 skrll

Add (back) -Wl,-static to the link.


# 1.73 03-Feb-2006 rpaulo

Remove -Wl,-non_shared (same meaing as -static).


# 1.72 04-Jun-2005 lukem

Explicitly prefix ld(1) options in LDFLAGS with "-Wl," rather than
using the ${LDFLAGS:@F@-Wl,$F@} make substitution because that breaks
if LDFLAGS is already set.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.71 11-Jan-2005 martin

Backout -DDEBUG that I accidently commited with the last change


# 1.70 09-Jan-2005 martin

Add LD_BIND_NOW support for sparc and remove some relocation types that
are not supposed to happen in 32bit code.
From Nick Hudson.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.69 24-Mar-2004 skrll

Be more pedantic about where we use -shared, etc.


# 1.68 26-Feb-2004 enami

Whitespace.


# 1.67 23-Feb-2004 skrll

Whitespace.


# 1.66 22-Feb-2004 uwe

Use CC instead of LD to link the ld.elf_so. This will correctly link
"millicode" from libgcc_pic.a on platforms that need it.

From Nick Hudson <skrll@netbsd>.


# 1.65 21-Feb-2004 skrll

Move common LDFLAGS into Makefile from arch/*/Makefile.inc


# 1.64 21-Oct-2003 lukem

Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.


# 1.63 19-Oct-2003 lukem

rework to use the newer _MKMSGCREATE (et al) macros


# 1.62 19-Oct-2003 lukem

support MAKEVERBOSE


# 1.61 25-Mar-2003 scw

Add support for shared libraries/dynamically linked binaries on sh5.
With the latest SuperH toolchain, NetBSD/evbsh5 can now
run with a fully dynamic userland (modulo a few remaining
gremlins affecting a couple of binaries).


# 1.60 26-Feb-2003 uwe

Do not add ${LIBC_PIC} to DPADD if MKPICINSTALL is "no".


Revision tags: fvdl_fs64_base
# 1.59 05-Oct-2002 junyoung

Disable DEBUG again.


# 1.58 05-Oct-2002 junyoung

Don't call _rtld_process_mapping() with null string.


# 1.57 27-Sep-2002 thorpej

Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located. Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only. SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.


# 1.56 26-Sep-2002 mycroft

*poof*
-fomit-frame-pointer works on 68k.


# 1.55 26-Sep-2002 mycroft

-vomit-frame-pointer is buggy on 68k. *sigh*


# 1.54 26-Sep-2002 mycroft

By default, compile without DEBUG, and with -fomit-frame-pointer.


# 1.53 13-Sep-2002 mycroft

Turn DEBUG back on by default. It doesn't take much space.


# 1.52 31-Aug-2002 mycroft

Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)


# 1.51 19-Aug-2002 lukem

Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path


# 1.50 10-Aug-2002 thorpej

Build for "armeb".


# 1.49 10-Jul-2002 fredette

Add support for dynamic linking on HP PA-RISC.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.48 01-Mar-2002 tv

branches: 1.48.2;
Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.


# 1.47 04-Feb-2002 thorpej

Use ${MACHINE_CPU} to assign ARCHSUBDIR.


# 1.46 03-Feb-2002 thorpej

Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.


# 1.45 23-Jan-2002 skrll

Install the man page on a.out systems as well so that the man set is the
same for all.


# 1.44 04-Jan-2002 tv

Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.


# 1.43 28-Dec-2001 lukem

- Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
${SHLIBDIR}:${LIBDIR}


# 1.42 28-Dec-2001 lukem

if SHLINKDIR != /usr/libexec, install compat symlink


# 1.41 28-Dec-2001 lukem

* Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed


# 1.40 14-Dec-2001 thorpej

Don't put compiler options into CPPFLAGS.


# 1.39 31-Oct-2001 skrll

Add a man page for ld.elf_so.


# 1.38 15-Jul-2001 matt

Enable arm if OBJECT_FMT is ELF. Initialize first few GOT entries for ARM.


# 1.37 19-Jun-2001 fvdl

Preliminary x86-64 support. Not fully functional yet (toolchain bugs).


# 1.36 14-Jan-2001 christos

back out previous commit; I found a better way of handling the missing
dependencies.


# 1.35 14-Jan-2001 christos

Don't use ${OBJS} in the dependency line, cause it is not defined yet.
Also add a .NOTMAIN for good measure.


# 1.34 10-Nov-2000 mycroft

When dlopen()ing with RTLD_GLOBAL, also make dependent libraries RTLD_GLOBAL.


# 1.33 14-Jul-2000 matt

Split DEBUG into two lines to make it easier to enable each separately.


# 1.32 03-Jul-2000 matt

If OBJECT_FMT is ELF and MACHINE_ARCH = vax, build ld.elf_so


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 1.31 26-Mar-2000 mycroft

Don't try to get libc_pic from the libc compile directory. If we're doing a
build, libc has already been installed.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.30 05-Jul-1999 thorpej

Protect certain definitions from view by crt0, by wrapping them in
#ifdef _RTLD_SOURCE.

Should fix the "variable page size" build error of crt0 on the SPARC.


# 1.29 07-May-1999 thorpej

Don't even make depend if we're not going to build ld.elf_so. this is
especially important if the assembler syntax is different.


# 1.28 29-Apr-1999 kleink

Always use ${MACHINE_ARCH} rather than ${MACHINE}, and reorder architectures
a bit.


# 1.27 29-Apr-1999 kleink

Add m68k code.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.26 19-Mar-1999 thorpej

Move the link.h files for the different shlib formats via repository copy,
and rename them to match the executable format. Introduce a new link.h
file which automatically picks the correct header based on the target of
the toolchain.


# 1.25 05-Mar-1999 drochner

make the mipse[lb]->mips translation really work,
thanks Izumi Tsutsui


# 1.24 03-Mar-1999 christos

Make this compile without -DRTLD_LOADER and fix printf format problems on
the alpha.


# 1.23 03-Mar-1999 jonathan

Makefile ${MACHINE_ARCH} changes for mips{eb,el}, as suggested by
Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>


# 1.22 24-Feb-1999 christos

Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c
Now we don't need to load at address 0 on the i386 and the mips should be
trivial to fix.


# 1.21 21-Feb-1999 kleink

Replace home-grown header file installation with INCS/INCSDIR; from Erik
Bertelsen in PR bin/6869.


# 1.20 13-Feb-1999 lukem

convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.


# 1.19 07-Feb-1999 christos

Add -DRTLD_DEBUG_RELOC commented out.


# 1.18 10-Jan-1999 christos

Add i386 bits


# 1.17 24-Nov-1998 tsubai

Add powerpc support.


# 1.16 13-Sep-1998 mrg

remove MD asm as(1) comments from sysident.h, placing them in a comment
above the asm() block. now we can share sysident.h across all ports..
change ld.elf_so to be for $MACHINE == sparc64 not sparc (yet!).


# 1.15 27-Aug-1998 tv

Use -L for libc's objdir in case NOPICINSTALL is set in mk.conf.


# 1.14 13-Aug-1998 christos

Don't install the ELF link.h in a.out systems!@#$#@


# 1.13 04-Aug-1998 tv

Use NOPIC to mean "no shared libraries", not NOSHLIB.


# 1.12 25-Mar-1998 mhitch

Add support for mips.


# 1.11 23-Feb-1998 jonathan

More table-driven changes for different toolchains:
* new bsd.own.mk variable OBJECT_FMT with values "a.out" or "ELF".
* use OBJECT_FMT in Makefile tests that depend on toolchain.
* Add new bsd.own.mk variable NOSHLIB that, if set indicates a given
port doesnt yet do shared libraries. Set on powerpc.
* Document new feature-test variables in src/share/mk/bsd.README.
Tested on i386, mips, fakedup Alpha environment.


# 1.10 25-Oct-1997 cjs

Link with the stuff we compiled, rather that whatever random stuff happens
to be installed on the system we're compiling on.


# 1.9 23-Oct-1997 jonathan

Install our ELF-aware link.h into /usr/include on mips hosts.


# 1.8 22-Oct-1997 lukem

use CPPFLAGS instead of CFLAGS


Revision tags: netbsd-1-3-base
# 1.7 23-Jun-1997 mrg

branches: 1.7.2;
move man pages into share/man.


# 1.6 31-May-1997 cjs

Back out BUILDDIR and NOINSTALL changes.


# 1.5 26-May-1997 cjs

branches: 1.5.2;
These updates to the build allow building against include files
and libs in the object tree, if you use a separate object tree,
while maintaining backward compatability with other build methods.
See the notes in src/share/mk/bsd.README for full details. Note
that the `make includes' target now only installs the include files
in the build directory (if you use one--otherwise they go in DESTDIR
just like before); `make install' will install include files in
DESTDIR.


# 1.4 17-Apr-1997 thorpej

STRIP -> STRIPFLAG (sign, I guess I forgot to check this one in last night)


# 1.3 10-Apr-1997 cgd

pull in arch-specific Makefile.inc only if it exists


# 1.2 24-Mar-1997 christos

- Makefile cleanups


# 1.1 16-Dec-1996 cgd

First cut at an ELF shared loader. Originally from John Polstra's FreeBSD elf
kit, then hacked on by Matt Thomas <matt@3am-software.com>, then by me (to
make it work with new versions of the toolchain, etc.). This runs, but it's
in serious need of cleaning and/or a fair bit of reworking. See the README
file for more information, and a list of things to do.