Commit Graph

13 Commits

Author SHA1 Message Date
Ryan Libby
bce2cff0bc rtld-elf: link udivmoddi4 from compiler_rt
This fixes the gcc9 build of rtld-elf32 on amd64, which needed an
implementation of udivmoddi4.

rtld-elf uses certain functions normally found in libc, and so it
includes certain files from libc in its own build.  It has two
mechanisms to include files from libc: one that rebuilds source files in
the rtld-elf environment, and one that extracts object files from a
purpose-built no-SSP PIC archive.

In addition to libc functions, rtld-elf may need to link functions
normally found in libcompiler_rt (formerly libgcc).  Now, add an ability
to rebuild libcompiler_rt source files in the rtld-elf environment.  We
don't yet have a need for an object file extraction mechanism.

libcompiler_rt could also supply udivdi3 and umoddi3, but leave them
alone for now.

Reviewed by:	arichardson, kib
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D27665
2020-12-19 08:38:31 +00:00
Ryan Libby
198a0e58ec rtld-libc: fix incremental build
ar cr is an update of an archive, not a creation of a new one.  During
incremental builds (e.g. with meta mode) the archive was not getting
cleaned, and so could retain now-deleted objects from previous builds.
Now, delete the archive before creating/updating it.

Reviewed by:	arichardson, bdrewery, kib
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D27663
2020-12-19 08:38:27 +00:00
Brandon Bergren
24faccc241 [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.
2020-09-23 00:21:51 +00:00
Konstantin Belousov
510b525fa5 rtld: set osrel when in the direct exec mode.
Rtld itself is a shared object which does not have vendor note, so
after the direct exec of ld-elf.so.1 process has p_osrel set to zero.
This affects the ABI of syscalls.

Set osrel to the __FreeBSD_version value at compile time right after
rtld identified direct exec mode.  Then, switch to the osrel read from
the binary note or zero if no note, right before starting calling
ifunc resolvers, which is the first byte of the user code.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2020-06-12 22:10:03 +00:00
Warner Losh
8e0ff10d4b Remove sparc64 specific parts of rtld-elf. 2020-02-26 18:49:25 +00:00
Mateusz Guzik
0573d0a9b8 vfs: add realpathat syscall
realpath(3) is used a lot e.g., by clang and is a major source of getcwd
and fstatat calls. This can be done more efficiently in the kernel.

This works by performing a regular lookup while saving the name and found
parent directory. If the terminal vnode is a directory we can resolve it using
usual means. Otherwise we can use the name saved by lookup and resolve the
parent.

See the review for sample syscall counts.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D23574
2020-02-20 16:58:19 +00:00
Konstantin Belousov
aef199e563 Use sigfastblock(2) in rtld.
This allows for rtld to not issue two sigprocmask(2) syscalls for each
symbol binding operation in single-threaded processes.  Rtld needs to
block signals as part of locking to ensure signal safety of the bind
process, because signal handlers might need to lazily resolve symbol
references.

As result, number of syscalls issued on startup by simple programs not
using libthr, is typically reduced 2x.  For instance, for hello world,
I see:
non-sigfastblock
# (truss ./hello > /dev/null) |& wc -l
      63
sigfastblock
# (truss ./hello > /dev/null) |& wc -l
      37

Tested by:	pho
Disscussed with:	cem, emaste, jilles
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D12773
2020-02-09 12:22:43 +00:00
Mateusz Guzik
da8e950a27 rtld: remove hand rolled memset and bzero
They were introduced to take care of ifunc, but right now no architecture
provides ifunc'ed variants. Since rtld uses memset extensively this results in
a pessmization. Should someone want to use ifunc here they should provide a
mandatory symbol (e.g., rtld_memset).

See the review for profiling data.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D23176
2020-01-15 01:30:32 +00:00
Kyle Evans
12ba1c232d rtld-elf: fix build with xtoolchain-llvm90
strstr ends up using bcmp when compiled with llvm90; pull it in from libc
as well.

MFC after:	3 days
2019-08-15 17:35:24 +00:00
Alex Richardson
0cc62e2695 Fix build race when building rtld
I found this on one of the CheriBSD Jenkins builders. Using
beforelinking instead of ${PROG} should fix the dependency for the
DEBUG_FILES case.

Reviewed by:	brooks
2019-07-02 22:11:07 +00:00
Alex Richardson
10faac99fb Fix CROSS_TOOLCHAIN=amd64-gcc build after r349554
Apparently clang can remove the reference to __umoddi3 but GCC keeps it.

Reported by:	lwhsu
2019-06-30 17:03:14 +00:00
Alex Richardson
e1470c8f96 Fix my name in license header
Reported by:	trasz
2019-06-30 14:04:30 +00:00
Alex Richardson
b54a59f3ba 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
2019-06-30 11:49:58 +00:00