History log of /freebsd-current/libexec/rtld-elf/Makefile
Revision Date Author Comments
# 9bfd3b40 12-May-2024 Kyle Evans <kevans@FreeBSD.org>

Add a build knob for _FORTIFY_SOURCE

In the future, we will Default to _FORTIFY_SOURCE=2 if SSP is enabled,
otherwise default to _FORTIFY_SOURCE=0. For now we default it to 0
unconditionally to ease bisect across older versions without the new
symbols, and we'll put out a call for testing.

include/*.h include their ssp/*.h equivalents as needed based on the
knob. Programs and users are allowed to override FORTIFY_SOURCE in their
Makefiles or src.conf/make.conf to force it off.

Reviewed by: des, markj
Relnotes: yes
Sponsored by: Stormshield
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D32308


# 5db5c6c8 28-Feb-2024 Konstantin Belousov <kib@FreeBSD.org>

rtld: use generated map file to check for some leaks from libc into rtld

Reviewed by: brooks, emaste (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D44136


# 79994015 27-Feb-2024 Konstantin Belousov <kib@FreeBSD.org>

rtld: unconditionally generate map file during build

It is needed at least to ensure that undesirable code is not linked into
rtld from libsys/libc, and adding the map file option each time is not
productive.

Reviewed by: brooks, emaste
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D44136


# 4a3cf5f3 12-Dec-2023 John Baldwin <jhb@FreeBSD.org>

Stop #defining FREEBSD_ELF

This was originally used (along with FREEBSD_AOUT) to prefer the use
of ELF in various tools instead of a.out as part of the a.out to ELF
transition in the 3.x days. The last use of it was removed from
<link.h> in commit 66422f5b7a1a6055f0b2358268eb902aab6e2e3e back in
2002, but various files still #define it.

Reviewed by: kevans, imp, emaste
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D42964


# d0b2dbfa 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line sh pattern

Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/


# 195e5054 26-Jul-2023 Jessica Clarke <jrtc27@FreeBSD.org>

libexec: Automatically generate rtld-elf list and generalise TAGS

Note that the pattern for matching is made slightly more specific, so as
to permit libcompats where one is a prefix of another (e.g. CheriBSD has
lib64 and lib64c).

Reviewed by: brooks, jhb, emaste, imp, kib
Differential Revision: https://reviews.freebsd.org/D41183


# ec1e8378 02-May-2023 Ed Maste <emaste@FreeBSD.org>

rtld: don't add extraneous -L directory when MK_TOOLCHAIN == no

rtld's Makefile used to add -L${LIBDIR} to LDFLAGS when MK_TOOLCHAIN was
no. This was done as part of a change to fix building rtld with
MK_TOOLCHAIN == no (although I'm not sure this part was necessary).

In any case as of 5f2e84015da7 libc_pic.a is built independent of the
MK_TOOLCHAIN setting and the main part of the workaround has already
been removed. Remove the rest now.

This reverts commit c0f5aeb0329d71e6b02379133c0c9c0145c9afea.

Reviewed by: jrtc27
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39938


# d0f0e0bd 13-Oct-2021 Emmanuel Vadot <manu@FreeBSD.org>

rtld: Do not install libmap.conf when installing the COMPAT32 version

This has the effect of installing the same file twice at the same location
and confuse pkgbase as we add this file twice in the package config part.

MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG


# 7bc797e3 02-Aug-2021 Alex Richardson <arichardson@FreeBSD.org>

Add build system support for ASAN+UBSAN instrumentation

This adds two new options WITH_ASAN/WITH_UBSAN that can be set to
enable instrumentation of all binaries with AddressSanitizer and/or
UndefinedBehaviourSanitizer. This current patch is almost sufficient
to get a complete buildworld with sanitizer instrumentation but in
order to actually build and boot a system it depends on a few more
follow-up commits.

Reviewed By: brooks, kib, markj
Differential Revision: https://reviews.freebsd.org/D31043


# 63f93c7e 28-Dec-2020 Ryan Libby <rlibby@FreeBSD.org>

rtld-elf: link libcompiler_rt on all architectures

Statically link rtld-elf with libcompiler_rt on all architectures so
that we don't need to try to pick and choose the bits we need from it
for each architecture (we now leave that to the linker). Compilers may
emit calls to support functions in this library, but because of the use
of the linker flag -nostdlib for rtld's special needs, the library is
not linked as normal.

Previously we had two different solutions. On some architectures, we
were able to extract reimplementations of the necessary builtin
functions from our special build of libc. On ARM, we just linked
libcompiler_rt.

This is motivated by the same issue as D26199 and D27665, but should be
a simpler solution that will apply to all architectures.

Reviewed by: arichardson, kib
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D27736


# 7cc42f6d 30-Sep-2020 Kyle Evans <kevans@FreeBSD.org>

Do a sweep and remove most WARNS=6 settings

Repeating the default WARNS here makes it slightly more difficult to
experiment with default WARNS changes, e.g. if we did something absolutely
bananas and introduced a WARNS=7 and wanted to try lifting the default to
that.

Drop most of them; there is one in the blake2 kernel module, but I suspect
it should be dropped -- the default WARNS in the rest of the build doesn't
currently apply to kernel modules, and I haven't put too much thought into
whether it makes sense to make it so.


# 24faccc2 22-Sep-2020 Brandon Bergren <bdragon@FreeBSD.org>

[PowerPC64LE] Use a shared LIBC_ARCH for powerpc64le.

Given that we have converted to ELFv2 for BE already, endianness is the only
difference between the two ARCHs.

As such, there is no need to differentiate LIBC_ARCH between the two.

Combining them like this lets us avoid needing to have two copies of several
bits for no good reason.

Sponsored by: Tag1 Consulting, Inc.


# 94179175 16-Aug-2020 Xin LI <delphij@FreeBSD.org>

Don't explicitly specify c99 or gnu99 as the default is now gnu99.

MFC after: 2 weeks


# e9751a84 16-Jul-2020 John Baldwin <jhb@FreeBSD.org>

Include FreeBSD ABI tag note in the ELF runtime loader.

Reviewed by: kib
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D25306


# fac6dee9 12-May-2020 Eric van Gyzen <vangyzen@FreeBSD.org>

Remove tests for obsolete compilers in the build system

Assume gcc is at least 6.4, the oldest xtoolchain in the ports tree.
Assume clang is at least 6, which was in 11.2-RELEASE. Drop conditions
for older compilers.

Reviewed by: imp (earlier version), emaste, jhb
MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D24802


# 5a77ce24 29-Apr-2020 Michal Meloun <mmel@FreeBSD.org>

Move ARM specific flags to arm/Makefile.inc

Requested by: kib
MFC with: r360463


# 7838a782 29-Apr-2020 Michal Meloun <mmel@FreeBSD.org>

Don't allow to use FPU inside of rtld library.
Clang10 may use FPU instructions for optimizing operations with
memory blocks. But we don't want to do lengthy save/restore of all
FPU registers across each rtld_start() call.

MFC after: 3 week


# 7e3300e5 11-Jan-2020 Konstantin Belousov <kib@FreeBSD.org>

rtld: clean up Makefile.

Move all MD statements into $MACHINE_ARCH/Makefile.inc.
Unconditionally apply version script to rtld, the interpreter is not
functional without it for long time.

Reviewed by: brooks, emaste
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D23083


# 051ed84f 12-Nov-2019 Brooks Davis <brooks@FreeBSD.org>

libcompat: Correct rtld MLINKS

Don't install duplicate ld-elf.so.1.1 and ld.so.1 links in rtld-elf32.
Do install lib-elf32.so.1.1 and ldd32.1 links.

Reported by: madpilot


# a4330302 07-Nov-2019 Brooks Davis <brooks@FreeBSD.org>

libcompat: build 32-bit rtld and ldd as part of "everything"

Alter bsd.compat.mk to set MACHINE and MACHINE_ARCH when included
directly so MD paths in Makefiles work. In the process centralize
setting them in LIBCOMPATWMAKEENV.

Alter .PATH and CFLAGS settings in work when the Makefile is included.

While here only support LIB32 on supported platforms rather than always
enabling it and requiring users of MK_LIB32 to filter based
TARGET/MACHINE_ARCH.

The net effect of this change is to make Makefile.libcompat only build
compatability libraries.

Changes relative to r354449:

Correct detection of the compiler type when bsd.compat.mk is used
outside Makefile.libcompat. Previously it always matched the clang
case.

Set LDFLAGS including the linker emulation for mips where -m32 seems to
be insufficent.

Reviewed by: imp, kib (origional version in r354449)
Obtained from: CheriBSD (conceptually)
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D22251


# ccad77fe 07-Nov-2019 Brooks Davis <brooks@FreeBSD.org>

Revert r354449: libcompat: build 32-bit rtld and ldd as part of "everything"

Additional testing is required..


# 36712a94 07-Nov-2019 Brooks Davis <brooks@FreeBSD.org>

libcompat: build 32-bit rtld and ldd as part of "everything"

Alter bsd.compat.mk to set MACHINE and MACHINE_ARCH when included
directly so MD paths in Makefiles work. In the process centralize
setting them in LIBCOMPATWMAKEENV.

Alter .PATH and CFLAGS settings in work when the Makefile is included.

While here only support LIB32 on supported platforms rather than always
enabling it and requiring users of MK_LIB32 to filter based
TARGET/MACHINE_ARCH.

The net effect of this change is to make Makefile.libcompat only build
compatability libraries.

Reviewed by: imp, kib
Obtained from: CheriBSD (conceptually)
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D22251


# b54a59f3 30-Jun-2019 Alex Richardson <arichardson@FreeBSD.org>

Reduce size of rtld by 22% by pulling in less code from libc

Currently RTLD is linked against libc_nossp_pic which means that any libc
symbol used in rtld can pull in a lot of depedencies. This was causing
symbol such as __libc_interposing and all the pthread stubs to be included
in RTLD even though they are not required. It turns out most of these
dependencies can easily be avoided by providing overrides inside of rtld.

This change is motivated by CHERI, where we have an experimental ABI that
requires additional relocation processing to allow the use of function
pointers inside of rtld. Instead of adding this self-relocation code to
RTLD I attempted to remove most function pointers from RTLD and discovered
that most of them came from the libc dependencies instead of being actually
used inside rtld.

A nice side-effect of this change is that rtld is now 22% smaller on amd64.

text data bss dec hex filename
0x21eb6 0xce0 0xe60 145910 239f6 /home/alr48/ld-elf-x86.before.so.1
0x1a6ed 0x728 0xdd8 113645 1bbed /home/alr48/ld-elf-x86.after.so.1

The number of R_X86_64_RELATIVE relocations that need to be processed on
startup has also gone down from 368 to 187 (almost 50% less).

Reviewed By: kib
Differential Revision: https://reviews.freebsd.org/D20663


# e3e21edb 14-Apr-2019 Konstantin Belousov <kib@FreeBSD.org>

ld-elf.so: make LD_DEBUG always functional.

This causes some increase of the dynamic linker size, but benefits of
avoiding compiling private copy or the linker when debugging is
required. definitely worth it.

The dbg() calls can be compiled out by defining LD_NO_DEBUG symbol.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 09b47fc1 27-Mar-2019 Ed Maste <emaste@FreeBSD.org>

revert r341429 "disable BIND_NOW in libc, libthr, and rtld"

r345620 by kib@ fixed the rtld issue that caused a crash at startup
during resolution of libc's ifuncs with BIND_NOW.

PR: 233333
Sponsored by: The FreeBSD Foundation


# bcf99d2d 15-Feb-2019 Ed Maste <emaste@FreeBSD.org>

Add WITH_PIE knob to build Position Independent Executables

Building binaries as PIE allows the executable itself to be loaded at a
random address when ASLR is enabled (not just its shared libraries).

With this change PIE objects have a .pieo extension and INTERNALLIB
libraries libXXX_pie.a.

MK_PIE is disabled for some kerberos5 tools, Clang, and Subversion, as
they explicitly reference .a libraries in their Makefiles. These can
be addressed on an individual basis later. MK_PIE is also disabled for
rtld-elf because it is already position-independent using bespoke
Makefile rules.

Currently only dynamically linked binaries will be built as PIE.

Discussed with: dim
Reviewed by: kib
MFC after: 1 month
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D18423


# d49ca25d 30-Jan-2019 Konstantin Belousov <kib@FreeBSD.org>

Rename rtld-elf/malloc.c to rtld-elf/rtld_malloc.c.

Then malloc.c file name is too generic to use it for libthr.a.

Sponsored by: The FreeBSD Foundation
MFC after: 13 days


# 0e450664 03-Dec-2018 Ed Maste <emaste@FreeBSD.org>

disable BIND_NOW in libc, libthr, and rtld

An issue remains with BIND_NOW and processes using threads. For now,
restore libc's BIND_NOW disable, and also disable BIND_NOW in rtld and
libthr.

A patch is in review (D18400) that likely fixes this issue, but just
disable BIND_NOW pending further testing after it is committed.

PR: 233333
Sponsored by: The FreeBSD Foundation


# c15faaac 23-Nov-2018 Conrad Meyer <cem@FreeBSD.org>

Revert r340843 - addressed independently in r340842!


# 66a87f8c 23-Nov-2018 Conrad Meyer <cem@FreeBSD.org>

rtld: Silence a false positive GCC 6.4.0 warning

The function reloc_non_plt has complicated variable lifetimes that GCC 6.4.0
(the version currently used by amd64-xtoolchain-gcc) misunderstands and
produces an erroneous warning about. Silence it to allow the -Werror build
to proceed.

Reviewed by: emaste


# 3ab5b6bd 29-Oct-2018 Alex Richardson <arichardson@FreeBSD.org>

rtld-elf: fix more warnings to allow compiling with WARNS=6

Reviewed By: kib
Approved By: brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17154


# 903e0ffd 29-Oct-2018 Alex Richardson <arichardson@FreeBSD.org>

rtld-elf: compile with WANRS=4 warnings other than -Wcast-align

Reviewed By: kib
Approved By: brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17153


# 9a537769 17-Sep-2018 Brad Davis <brd@FreeBSD.org>

Move libmap.conf to libexec/rtld-elf/

This leverages CONFS to handle the config file install.

Approved by: re (gjb), will (mentor)
Differential Revision: https://reviews.freebsd.org/D17161


# 0725fca5 09-May-2018 Konstantin Belousov <kib@FreeBSD.org>

Make rtld use libc_nossp_pic.a. Remove SSP shims.

Submitted by: Luis Pires
Reviewed by: brooks
Differential revision: https://reviews.freebsd.org/D15341


# f4711b38 30-Aug-2017 John Baldwin <jhb@FreeBSD.org>

Compile reloc.o with -fno-jump-tables on MIPS.

In particular, the switch statement on the type of dynamic entries
in _rtld_relocate_nonplt_self() needs to not use a jump table since
jump tables on MIPS use local GOT entries which aren't initialized
until after this loop.

Suggested by: arichardson
Reviewed by: emaste
Sponsored by: DARPA / AFRL


# cb68e175 17-Aug-2017 Enji Cooper <ngie@FreeBSD.org>

Explicitly disable MK_COVERAGE

This doesn't work with --coverage enabled. It still doesn't link, but this
reduces the linker errors from 50~100 to 1.


# d511b20a 02-Aug-2017 Enji Cooper <ngie@FreeBSD.org>

Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.


# 4b330699 02-Aug-2017 Enji Cooper <ngie@FreeBSD.org>

Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after: 1 weeks


# ce9f2d31 06-Mar-2017 Rodney W. Grimes <rgrimes@FreeBSD.org>

Convert absolute links to relative links.
Style.Makefile(9) has been ignored to produce minimal diffs.

Approved by: grehan (mentor)
MFC after: 1 week


# 4562cfc4 15-Nov-2016 Konstantin Belousov <kib@FreeBSD.org>

Assert that there is no unresolved symbols during rtld linking.

Reviewed by: emaste, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
X-Differential revision: https://reviews.freebsd.org/D8448


# 093513c7 15-Nov-2016 Konstantin Belousov <kib@FreeBSD.org>

Update hint to utilize user variable.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# e7debdcb 03-Jul-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Fix race for incrementally rebuilding VERSION_MAP.

The dependency is needed in PROG_FULL since only the build of PROG_FULL
is using the LDFLAGS and depending on VERSION_MAP. This was not a problem
with MK_DEBUG_FILES==no since it only builds PROG.

This should probably be using bsd.lib.mk instead [1]

Reported by: swills, gjb
Reviewed by: emaste
Noted by: rgrimes [1]
Sponsored by: EMC / Isilon Storage Division
Approved by: re (kib)


# c0f5aeb0 31-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

WITHOUT_TOOLCHAIN: Fix build of rtld.

MK_TOOLCHAIN==no disables building and installing of pic archives.
c_pic.a is still needed for rtld though so force it to build in lib/libc
and link directly to the objdir version of it for rtld.

Somehow this has been broken since r148725.

Sponsored by: EMC / Isilon Storage Division


# c389411c 05-Feb-2016 Glen Barber <gjb@FreeBSD.org>

Remove libc, librtld_db, libthr packages, and further increase
the constraints on what needs to be installed in a specific to
maintain consistency during upgrades.

Create a new clibs package containing libraries that are needed
as a bare minimum for consistency.

With much help and input from: kib
Sponsored by: The FreeBSD Foundation


# 393303e3 04-Feb-2016 Glen Barber <gjb@FreeBSD.org>

Include ld-elf.so and ld-elf32.so in the librtld_db
package.

Sponsored by: The FreeBSD Foundation


# 4cce0e98 03-Dec-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Follow-on to r291666: use -ffreestanding instead of -fno-builtin.

Requested by: kib


# 50ea11fc 02-Dec-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Fix build on GCC 5.2 where, at least on PPC64, the compiler would "optimize"
the malloc() + memset() in the local implementation of calloc() into a call
to calloc(), helpfully turning it into an infinite loop. Clean up some
unneeded flags on PPC64 while here.

MFC after: 1 month


# 056b7d85 01-Dec-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Fix build after r291620.

"don't know how to make /Versions.def. Stop"

This was trying to define a target in bsd.symver.mk based on LIBCDIR which was
not yet defined. Switching the order of inclusion of bsd.prog.mk and
bsd.symver.mk fixes it and seems fine.

Pointyhat to: bdrewery
Sponsored by: EMC / Isilon Storage Division


# 3c89d6b0 01-Dec-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Don't override LIB*DIR variables from src.libnames.mk.

In some cases switch to the LIB*SRCDIR value.

These recently were defined in r291327 and r291619.

Sponsored by: EMC / Isilon Storage Division


# 7fdd45b0 25-Nov-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Use LIBEXECDIR for /usr/libexec.

MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division


# 1508ab98 18-Sep-2015 Bryan Drewery <bdrewery@FreeBSD.org>

META_MODE: No need to fix the link in this case.

The exists(${DESTDIR}...) check runs with DESTDIR being blank. When the
target runs it does have DESTDIR=${STAGE_OBJTOP} via bsd.sys.mk. This
results in the first execution warning that the symlink is missing. The
second run does run fine. However, this chflags is not needed at all
for META_MODE/STAGING since we never had this path being a schg file
while using META_MODE.

Sponsored by: EMC / Isilon Storage Division


# 0c4f9ecd 29-Mar-2015 Konstantin Belousov <kib@FreeBSD.org>

Change compiler setting to make default visibility of the symbols for
rtld on x86 to be hidden. This is a micro-optimization, which allows
intrinsic references inside rtld to be handled without indirection
through PLT. The visibility of rtld symbols for other objects in the
symbol namespace is controlled by a version script.

Reviewed by: kan, jilles
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks


# ee5a34ec 25-Nov-2014 Baptiste Daroussin <bapt@FreeBSD.org>

Convert to LIBADD
Reduce overlinking


# 6d4766c1 01-Oct-2014 Andrew Turner <andrew@FreeBSD.org>

Remove MK_ARM_EABI, the armeb issues have been fixed. The code to support
the oabi is still in the tree, but it is expected this will be removed
as developers work on surrounding code.

With this commit the ARM EABI is the only supported supported ABI by
FreeBSD on ARMa 32-bit processors.

X-MFC after: never
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D876


# d3b06cf2 29-Aug-2014 Konstantin Belousov <kib@FreeBSD.org>

Document the whole settings needed to build a debug version of rtld.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 5608fd23 19-Aug-2014 Bryan Drewery <bdrewery@FreeBSD.org>

Revert r267233 for now. PIE support needs to be reworked.

1. 50+% of NO_PIE use is fixed by adding -fPIC to INTERNALLIB and other
build-only utility libraries.
2. Another 40% is fixed by generating _pic.a variants of various libraries.
3. Some of the NO_PIE use is a bit absurd as it is disabling PIE (and ASLR)
where it never would work anyhow, such as csu or loader. This suggests
there may be better ways of adding support to the tree. Many of these
cases can be fixed such that -fPIE will work but there is really no
reason to have it in those cases.
4. Some of the uses are working around hacks done to some Makefiles that are
really building libraries but have been using bsd.prog.mk because the code
is cleaner. Had they been using bsd.lib.mk then NO_PIE would not have
been needed.

We likely do want to enable PIE by default (opt-out) for non-tree consumers
(such as ports). For in-tree though we probably want to only enable PIE
(opt-in) for common attack targets such as remote service daemons and setuid
utilities. This is also a great performance compromise since ASLR is expected
to reduce performance. As such it does not make sense to enable it in all
utilities such as ls(1) that have little benefit to having it enabled.

Reported by: kib


# 6b22f423 20-Jun-2014 Jonathan Anderson <jonathan@FreeBSD.org>

Test RTLD's new LD_LIBRARY_PATH_FDS variable.

Test LD_LIBRARY_PATH_FDS by linking a binary that requires a shared
library that isn't in any of the usual search paths. Ensure this fails
when we don't supply LD_LIBRARY_PATH_FDS or we pass invalid information
in it. Ensure it works when we pass the correct directory in various
places in the variable.

Approved by: rwatson (mentor)
MFC after: 3 weeks
Sponsored by: DARPA/AFRL


# 864c53ea 08-Jun-2014 Bryan Drewery <bdrewery@FreeBSD.org>

In preparation for ASLR [1] support add WITH_PIE to support building with -fPIE.

This is currently an opt-in build flag. Once ASLR support is ready and stable
it should changed to opt-out and be enabled by default along with ASLR.

Each application Makefile uses opt-out to ensure that ASLR will be enabled by
default in new directories when the system is compiled with PIE/ASLR. [2]

Mark known build failures as NO_PIE for now.

The only known runtime failure was rtld.

[1] http://www.bsdcan.org/2014/schedule/events/452.en.html
Submitted by: Shawn Webb <lattera@gmail.com>
Discussed between: des@ and Shawn Webb [2]


# c6063d0d 05-May-2014 Warner Losh <imp@FreeBSD.org>

Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.


# 37656b87 18-Jan-2014 Ed Schouten <ed@FreeBSD.org>

Replace LIBGCC by LIBCOMPILER_RT.

We now use libcompiler_rt on all platforms now. Instead of referring
directly to -lgcc and LIBGCC, use -lcompiler_rt and LIBCOMPILER_RT.


# de2be60c 18-Jan-2013 Andrew Turner <andrew@FreeBSD.org>

When building for ARM EABI link against libgcc for the __aeabi_* functions.


# 456b64c4 04-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Use absolute path for /usr/libexec/ld-elf.so.1 symlink.

Requested by: kan, kib

Use -h flags for chflags, so we won't remove 'schg' flag from system's
/libexec/ld-elf.so.1.

MFC after: 2 weeks


# f31c1e3f 03-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Do not change entire BINDIR, it might be needed later, just change
symlink target.

MFC after: 2 weeks


# dee63064 03-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Change /usr/libexec/ld-elf.so.1 to point at ../../libexec/ld-elf.so.1
instead of /libexec/ld-elf.so.1. Below in the Makefile we execute
'chflags noschg ${DESTDIR}/usr/libexec/ld-elf.so.1', which follows
symlink and removes 'schg' flag from system's /libexec/ld-elf.so.1
instead of the one in DESTDIR. It is also more friendly to use
replative paths in symlink in case of jail/chroot environments.

Obtained from: WHEEL Systems
MFC after: 2 weeks


# 2aa3a467 24-Mar-2012 Konstantin Belousov <kib@FreeBSD.org>

Remove libssp_nonshared from the rtld linking set. The only use for the
library was definition for the weak alias of __stack_chk_fail.

No objections from: kan
MFC after: 2 weeks


# f7c419f2 22-Mar-2012 Konstantin Belousov <kib@FreeBSD.org>

Centralize the calculation of the top source directory. This
simplifies the build of rtld with partial checkout, allowing to
override only one place to reference other tree.

Submitted by: bde
MFC after: 2 weeks


# 83aa9cc0 11-Mar-2012 Konstantin Belousov <kib@FreeBSD.org>

Add support for preinit, init and fini arrays. Some ABIs, in
particular on ARM, do require working init arrays.

Traditional FreeBSD crt1 calls _init and _fini of the binary, instead
of allowing runtime linker to arrange the calls. This was probably
done to have the same crt code serve both statically and dynamically
linked binaries. Since ABI mandates that first is called preinit
array functions, then init, and then init array functions, the init
have to be called from rtld now.

To provide binary compatibility to old FreeBSD crt1, which calls _init
itself, rtld only calls intializers and finalizers for main binary if
binary has a note indicating that new crt was used for linking. Add
parsing of ELF notes to rtld, and cache p_osrel value since we parsed
it anyway.

The patch is inspired by init_array support for DragonflyBSD, written
by John Marino.

Reviewed by: kan
Tested by: andrew (arm, previous version), flo (sparc64, previous version)
MFC after: 3 weeks


# 0e9a2605 24-Aug-2011 Konstantin Belousov <kib@FreeBSD.org>

Rtld links with the specially built pic static libc library to get some
C runtime services, like printf(). Unfortunately, the multithread-safeness
measures in the libc do not work in rtld environment.

Rip the kernel printf() implementation and use it in the rtld instead of
libc version. This printf does not require any shared global data and thus
is mt-safe. Systematically use rtld_printf() and related functions, remove
the calls to err(3).

Note that stdio is still pulled from libc due to libmap implementaion using
fopen(). This is safe but unoptimal, and can be changed later.

Reported and tested by: pgj
Diagnosed and reviewed by: kan (previous version)
Approved by: re (bz)


# f33b8de1 08-Jun-2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Compile RTLD with global dot symbols on 64-bit PowerPC, as a crutch for
GDB's ability to locate r_debug_state (which is actually the only function
that need be compiled this way).


# 06786ccf 25-Dec-2010 Konstantin Belousov <kib@FreeBSD.org>

Add a hook to pass debug flags to the build of rtld when doing make in
the rtld directory.

Reviewed by: kan


# b9c727d8 11-Nov-2010 Dimitry Andric <dim@FreeBSD.org>

Use -fPIC to build libexec/rtld-elf on sparc64, so it will also be able
to link with newer binutils, without overflowing the GOT.

Obtained from: projects/binutils-2.17


# f4fd60a2 30-Oct-2010 Dimitry Andric <dim@FreeBSD.org>

Use -fPIC for rtld-elf, so it can link on sparc64.


# 30ec71ad 21-Oct-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Unbreak ia64.

With r169630 I disabled symbol versioning because it broke rtld. With
r211706 rtld got broken for ia64 & powerpc64. It was fixed for powerpc64
with r212497. In between, r211749 removed the exports table because the
version script handled the exports. But wait, symbol versioning was
disabled on ia64.

With exports controlled by the version script and symbol versioning
disabled, all symbols are exported and too many symbols bind to the
definition in rtld. Let's just say that waird things happen.

So, enable symbol versioning on ia64 and apply a work-around for the
SIGSEGV that triggered r169630 to begin with: when rtld relocates
itself, it comes across r_debug_state and for some reason can't find the
definition. This causes a failure, relocation aborts and null pointers
galore. The work-around is to ignore the missing definition when rtld
is relocating itself and keep going.

Maybe with the next binutils this will all go away. Maybe not, in
which case I still need to figure out why r_debug_state cannot be found.

BTW: r_debug_state is in the symbol map -- I don't think any other rtld
symbols that rtld references are in the symbol map...


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 789e8545 24-Aug-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Make RTLD work on powerpc64 again. If there is a sub-directory named
MACHINE_ARCH, use that specific one, otherwise use MACHINE_CPUARCH.

Reviewed by: imp


# 25faff34 23-Aug-2010 Warner Losh <imp@FreeBSD.org>

MFtbemd:

Prefer MACHNE_CPUARCH to MACHINE_ARCH in most contexts where you want
to test of all the CPUs of a given family conform.


# 27bd4146 10-Jul-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

RTLD support for powerpc64. A few small modifications to the Makefile
and symbol map are required to support various consequences of the dot
symbol scheme:

- Symbols beginning with a dot are reserved, so start private symbols with
an underscore.
- In order to set RTLD breakpoints, gdb must be able to locate the text
entry point, not the data section function descriptor, so add
.r_debug_state to the symbol map on powerpc64.

Obtained from: projects/ppc64


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 1100c001 02-Jan-2010 Ed Schouten <ed@FreeBSD.org>

Make WARNS=6 the default for libexec/.

Just like bin/ and sbin/, I think setting WARNS to the highest value
possible will make it more attractive for people to fix warnings.

- The WARNS variable is set in the Makefile in the directory of the
application itself, making it more likely that it will be removed out
of curiosity to see what happens.
- New applications will most likely build with WARNS=6 out of the box,
because the author would more likely fix the warnings during
development than lower WARNS.

Unfortunately almost all apps in libexec require a lowered value of
WARNS.


# 2286fe76 14-Jul-2009 Alexander Kabaev <kan@FreeBSD.org>

Second attempt at eliminating .text relocations in shared libraries
compiled with stack protector.

Use libssp_nonshared library to pull __stack_chk_fail_local symbol into
each library that needs it instead of pulling it from libc. GCC
generates local calls to this function which result in absolute
relocations put into position-independent code segment, making dynamic
loader do extra work every time given shared library is being relocated
and making affected text pages non-shareable.

Reviewed by: kib
Approved by: re (kib)


# d48890cf 28-Jun-2009 Alexander Kabaev <kan@FreeBSD.org>

Back out previous revision until better tested fix is ready.

Approved by: re (impliciti, by approving previos check-in)


# a162c9ae 28-Jun-2009 Alexander Kabaev <kan@FreeBSD.org>

Eliminate .text relocations in shared libraries compiled with stack protector.

Use libssp_nonshared library to pull __stack_chk_fail_local symbol into
each library that needs it instead of pulling it from libc. GCC generates
local calls to this function which result in absolute relocations put into
position-independent code segment, making dynamic loader do extra work everys
time given shared library is being relocated and making affected text pages
non-shareable.

Reviewed by: kib
Approved by: re (kensmith)


# d9ca85fc 21-Feb-2009 Ruslan Ermilov <ru@FreeBSD.org>

Fix build when WITH_SSP is set explicitly.

Submitted by: Jeremie Le Hen


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 042df2e2 25-Jun-2008 Ruslan Ermilov <ru@FreeBSD.org>

Enable GCC stack protection (aka Propolice) for userland:
- It is opt-out for now so as to give it maximum testing, but it may be
turned opt-in for stable branches depending on the consensus. You
can turn it off with WITHOUT_SSP.
- WITHOUT_SSP was previously used to disable the build of GNU libssp.
It is harmless to steal the knob as SSP symbols have been provided
by libc for a long time, GNU libssp should not have been much used.
- SSP is disabled in a few corners such as system bootstrap programs
(sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves.
- It should be safe to use -fstack-protector-all to build world, however
libc will be automatically downgraded to -fstack-protector because it
breaks rtld otherwise.
- This option is unavailable on ia64.

Enable GCC stack protection (aka Propolice) for kernel:
- It is opt-out for now so as to give it maximum testing.
- Do not compile your kernel with -fstack-protector-all, it won't work.

Submitted by: Jeremie Le Hen <jeremie@le-hen.org>


# cc09c7fb 16-May-2007 Marcel Moolenaar <marcel@FreeBSD.org>

Don't enable symbol versioning on ia64 for now. It causes
symbol lookup failures that later result in null-pointer
dereferences. This needs looking into, but since we're
close to release it's possible that it's not resolved before
that time.


# 00fb440c 13-May-2007 Daniel Eischen <deischen@FreeBSD.org>

Enable symbol versioning by default. Use WITHOUT_SYMVER to disable it.
Warning, after symbol versioning is enabled, going back is not easy
(use WITHOUT_SYMVER at your own risk).

Change the default thread library to libthr.

There most likely still needs to be a version bump for at least the
thread libraries. If necessary, this will happen later.


# effa5b4e 29-Apr-2007 Alexander Kabaev <kan@FreeBSD.org>

Retire rtld-specific Versions.def. Symbols exported by rtld are supposed
to override weak symbols exported by libc, so by definition these two
are using the same symbol version names.

Reflect the reality by referring to libc's Versions.def directly.


# 3c0d0ca7 09-Apr-2007 Alexander Kabaev <kan@FreeBSD.org>

Bring rtld exports in line with corresponding symbols exported from
libc.

Disable SYMVER_DEFAULT n rtld until its implications are understood
better.


# 7ca8e6a6 03-Apr-2007 Alexander Kabaev <kan@FreeBSD.org>

Prepare rtld for symbol versioning. Disable it by default for now.


# 1b1aa7e4 14-Nov-2004 Ruslan Ermilov <ru@FreeBSD.org>

So do it like we do in usr.bin/tip/tip/Makefile. ;)


# 443ceb1c 14-Nov-2004 Jens Schweikhardt <schweikh@FreeBSD.org>

Revert previous commit. As ru explains:

In the old world (as the surrounding comment in makefile says), there
was the /usr/libexec/ld-elf.so.1 binary which is now a symlink to
/libexec/ld-elf.so.1. To symlink, we need to make sure that the
_target_ (and the target is /usr/libexec/ld-elf.so.1) doesn't have
"schg" flag set. A real solution is to protect the chflags call only if
target exists, like we do in usr.bin/tip/tip/Makefile.

Requested by: ru


# 6ccc491b 13-Nov-2004 Jens Schweikhardt <schweikh@FreeBSD.org>

Avoid an (ignored) error by invoking chflags on the link target, not the
symlink.

PR: kern/73016
Submitted by: John E. Hein <jhein@timing.com>
MFC after: 1 week


# dee651eb 03-Nov-2004 Ruslan Ermilov <ru@FreeBSD.org>

Introduce the PRECIOUSPROG knob in bsd.prog.mk, similar
to PRECIOUSLIB from bsd.lib.mk. The side effect of this
is making installing the world under jail(8) possible by
using another knob, NOFSCHG.

Reviewed by: oliver


# a35d8893 24-Oct-2004 Ruslan Ermilov <ru@FreeBSD.org>

For variables that are only checked with defined(), don't provide
any fake value.


# 45ab3f53 17-Jun-2004 Olivier Houchard <cognet@FreeBSD.org>

This comment should have been removed in the previous commit.

Spotted out by: marcus, simon


# f77d42ce 17-Jun-2004 Olivier Houchard <cognet@FreeBSD.org>

Woohoo !
the latest binutils import mades this gross hack useless, so just remove it.


# 3088dadd 14-May-2004 Olivier Houchard <cognet@FreeBSD.org>

Work around a problem somewhere with binutils (?) on arm, hopefully without
breaking any other arch this time.


# 55a4ccf3 14-May-2004 Stefan Eßer <se@FreeBSD.org>

Fix breakage caused by alphabetically sorting SRCS: rtld_start.S must come first!
The previous version made all shared binaries dump core.


# e659267f 13-May-2004 Olivier Houchard <cognet@FreeBSD.org>

Import arm bits for rtld-elf.

Obtained from: NetBSD


# c905e45d 20-Mar-2004 Peter Wemm <peter@FreeBSD.org>

Add initial support for compiling a special 32 bit version of
ld-elf.so.1 on 64 bit systems. Most of this involves using alternate
paths, environment variables and diagnostic messages.

The build glue is seperate.


# 5515f48c 13-Sep-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Retire the WITH_LIBMAP compile knob; libmap is now a standard feature.


# df7bdd0a 17-Aug-2003 Gordon Tetlow <gordon@FreeBSD.org>

Forgot one instance of ld-elf.so.1. Convert to ${PROG}

Pointed out by: obrien


# dbbcd515 17-Aug-2003 Gordon Tetlow <gordon@FreeBSD.org>

Don't forget to honor DESTDIR. Also switch over to using PROG instead of
the binary name directly.


# a857d930 17-Aug-2003 Gordon Tetlow <gordon@FreeBSD.org>

Don't forget to chflags noschg the existing binary so we can symlink
over it safely.

Pointed out by: yosimoto@waishi.jp


# df7c0368 17-Aug-2003 Gordon Tetlow <gordon@FreeBSD.org>

As long threatened, stage 2 of making a dynamically-linked root a reality.
Install rtld into /libexec.


# 8f17707c 03-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Set CSTD to gnu99. We can only use on of the gnu?9 C languages.
We can't use c89 due to use of 'inline', and c99 produces bad code.


# 6d5d786f 29-May-2003 Alexander Kabaev <kan@FreeBSD.org>

Allow threading libraries to register their own locking
implementation in case default one provided by rtld is
not suitable.

Consolidate various identical MD lock implementation into
a single file using appropriate machine/atomic.h.

Approved by: re (scottl)


# 29ade362 07-Apr-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Dynamic object dependency mapping: libmap.

This is an optional feature, disabled by default.

This will be useful to people testing the various POSIX threading
libraries under -CURRENT but can easily serve other needs.


# d9943f16 13-Feb-2003 Alexey Zelkin <phantom@FreeBSD.org>

Advertize rtld(1) as ld.so(1) in manual pages world


# 5f8aa32e 10-Jun-2002 John Polstra <jdp@FreeBSD.org>

Dillon's recent commits to the dynamic linker without running them
by me first have given me a good excuse to drop my MAINTAINERship.

MFC after: 1 week


# 4cf39050 28-May-2001 Ruslan Ermilov <ru@FreeBSD.org>

Use new backup feature of install(1).


# e5b5c66b 26-Mar-2001 Ruslan Ermilov <ru@FreeBSD.org>

- Backout botched attempt to intoduce MANSECT feature.
- MAN[1-9] -> MAN.


# 119fc1a3 20-Jul-2000 Brian Feldman <green@FreeBSD.org>

We shouldn't use cp to save the old ld-elf.so.1. Use the sanctioned tool
${INSTALL} with -C -p instead.


# 517191ee 07-Jul-2000 John Polstra <jdp@FreeBSD.org>

When installing the dynamic linker, save the previous version in
"ld-elf.so.1.old". The dynamic linker is a critical component of
the system, and it is difficult to recover if it is damaged and
there isn't a working backup available. For instance, parts of
the toolchain such as the assembler are dynamically linked, making
it impossible to build a new dynamic linker if the installed one
doesn't work.


# 9d085703 27-Mar-2000 Bruce Evans <bde@FreeBSD.org>

Fixed missing DPADDs.

Fixed some style bugs (some usual ones for LDADD, and misformatting of
$FreeBSD$).


# ea5cc7f1 28-Jan-2000 John Polstra <jdp@FreeBSD.org>

Add a manual page for the ELF dynamic linker. I initially created
rtld.1 by means of a repository copy from "src/libexec/rtld-aout/rtld.1".
Then I edited it to make it (more) accurate for the ELF dynamic
linker.


# d3980376 26-Dec-1999 John Polstra <jdp@FreeBSD.org>

Add a new function dllockinit() for registering thread locking
functions to be used by the dynamic linker. This can be called by
threads packages at start-up time. I will add the call to libc_r
soon.

Also add a default locking method that is used up until dllockinit()
is called. The default method works by blocking SIGVTALRM, SIGPROF,
and SIGALRM in critical sections. It is based on the observation
that most user-space threads packages implement thread preemption
with one of these signals (usually SIGVTALRM).

The dynamic linker has never been reentrant, but it became less
reentrant in revision 1.34 of "src/libexec/rtld-elf/rtld.c".
Starting with that revision, multiple threads each doing lazy
binding could interfere with each other. The usual symptom was
that a symbol was falsely reported as undefined at start-up time.
It was rare but not unseen. This commit fixes it.


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 18cd0551 09-Jul-1999 John Polstra <jdp@FreeBSD.org>

Add a MAINTAINER line naming myself. We control the vertical. We
control the horizontal.


# d5b537d0 08-Apr-1999 John Polstra <jdp@FreeBSD.org>

Eliminate all machine-dependent code from the main source body and
the Makefile, and move it down into the architecture-specific
subdirectories.

Eliminate an asm() statement for the i386.

Make the dynamic linker work if it is built as an executable instead
of as a shared library. See i386/Makefile.inc to find out how to
do it. Note, this change is not enabled and it might never be
enabled. But it might be useful in the future. Building the
dynamic linker as an executable should make it start up faster,
because it won't have any relocations. But in practice I suspect
the difference is negligible.


# 0b8dcbe2 14-Feb-1999 Nate Williams <nate@FreeBSD.org>

- Set the system immutable flag when installing ld.so to avoid people
accidentally clobbering it.

Submitted by: numberous people on -current


# 13575fc4 04-Sep-1998 Doug Rabson <dfr@FreeBSD.org>

Add alpha support.

Submitted by: John Birrell <jb@cimlogic.com.au> (with extra hacks by me)
Obtained from: Probably NetBSD


# 9d5aee94 16-Aug-1998 John Polstra <jdp@FreeBSD.org>

Add "-C" to INSTALLFLAGS to install atomically. An elf->elf
installworld dies at this point otherwise, leaving the system
without a dynamic linker.


# 2001f720 30-Apr-1998 Doug Rabson <dfr@FreeBSD.org>

Add GDB support. The method and some of the code came from NetBSD's elf
runtime linker.


# 3124c3e0 07-Mar-1998 John Polstra <jdp@FreeBSD.org>

Import the ELF dynamic linker. This is the ElfKit version with
quite a few enhancements and bug fixes. There are still some known
deficiencies, but it should be adequate to get us started with ELF.

Submitted by: John Polstra <jdp@polstra.com>