Changeset View
Standalone View
sys/tools/amd64_vdso.sh
- This file was added.
#!/bin/sh | |||||
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||||
jrtc27: I feel like these should probably just be normal makefile rules; is there a reason they're not? | |||||
Done Inline ActionsThis is how I (tried to) do it initially. It appeared to be too painful to use for dev/debugging purposes. With the script, I can do rebuild after tweaking linker options manually within less than 1 sec, while with files.XXX and custom target I need to reconfigure/depend/buildkernel often with removal of the build directory. [Almost 60% of the time spent on this patch was with making linkers do what I wanted, both lld and ld.bfd] kib: This is how I (tried to) do it initially. It appeared to be too painful to use for… | |||||
# | |||||
# Copyright (c) 2021 The FreeBSD Foundation | |||||
# All rights reserved. | |||||
# | |||||
# This software was developed by Konstantin Belousov <kib@FreeBSD.org> | |||||
# under sponsorship from the FreeBSD Foundation. | |||||
# | |||||
# Redistribution and use in source and binary forms, with or without | |||||
# modification, are permitted provided that the following conditions | |||||
# are met: | |||||
# 1. Redistributions of source code must retain the above copyright | |||||
# notice, this list of conditions and the following disclaimer. | |||||
# 2. Redistributions in binary form must reproduce the above copyright | |||||
# notice, this list of conditions and the following disclaimer in the | |||||
# documentation and/or other materials provided with the distribution. | |||||
# | |||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
Done Inline ActionsUse a template asm file rather than the slightly hacky objcopy approach? (I guess a sys/kern/vdso.S a la sys/kern/firmw.S) jrtc27: Use a template asm file rather than the slightly hacky objcopy approach? (I guess a… | |||||
Done Inline ActionsWhat's wrong with objcopy? acpi trampoline uses the same way to generate .o from binary. Hm, the one thing that is better with firmw.S is that it all goes to .rodata instead of .data. I will consider it later, this is a little tweak in big picture. kib: What's wrong with objcopy? acpi trampoline uses the same way to generate .o from binary.
Hm… | |||||
Done Inline ActionsAs for why objcopy isn't the best: for architectures that have more than one ABI, e_flags stores the ABI and needs to match what it's linked with. objcopy doesn't have a way to pass a precise -mabi, so you just get a bunch of zeroes which is often, but not always, what the kernel wants. It's not a problem for amd64, but we've been purging all uses of objcopy for this purpose in MI places as all our pure-capability CHERI kernels have an ABI that's not encoded as 0 downstream, so if this is ever going to hit arm64 or riscv then it will become a problem. And yes, as you say, template asm files give you full control over exactly what you export and how, whereas objcopy just gives you whatever binutils maintainers decided 20+ years ago might make sense and hard-coded into the tool that LLVM and elftoolchain had to copy. jrtc27: As for why objcopy isn't the best: for architectures that have more than one ABI, e_flags… | |||||
Done Inline Actionsstat isn't a bootstrap tool, and on Linux it's stat -c %s, so this will break the cross-build support. I think wc -c is the only portable way to do this? jrtc27: stat isn't a bootstrap tool, and on Linux it's stat -c %s, so this will break the cross-build… | |||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
# SUCH DAMAGE. | |||||
set -e | |||||
${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \ | |||||
-o sigtramp.pico -I. -I"${S}" -include opt_global.h \ | |||||
"${S}"/amd64/amd64/sigtramp.S | |||||
# We need to make vdso as compact as possible, for it to leave space | |||||
# for other things in the shared page. For this, we pack everything | |||||
# into single loadable segment. | |||||
# | |||||
# -z rodynamic is undocumented lld-specific option, seemingly required | |||||
# for lld to avoid putting dynamic into dedicated writeable segment, | |||||
# despite ldscript placement. It is ignored by ld.bfd but ldscript | |||||
# alone is enough there. | |||||
# | |||||
${LD} --shared -Bsymbolic -soname="elf-vdso.so.1" \ | |||||
-T "${S}"/conf/vdso_amd64.ldscript \ | |||||
--eh-frame-hdr --no-undefined -z rodynamic -z norelro -nmagic \ | |||||
--hash-style=sysv --fatal-warnings --strip-all \ | |||||
-o elf-vdso.so.1 sigtramp.pico | |||||
if [ "$(wc -c elf-vdso.so.1 | ${AWK} '{print $1}')" -gt 2048 ] | |||||
then | |||||
Done Inline Actionswc -c < elf-vdso.so.1 won't print the file name, if you care about having to have the awk jrtc27: wc -c < elf-vdso.so.1 won't print the file name, if you care about having to have the awk | |||||
Done Inline ActionsI prefer awk kib: I prefer awk | |||||
echo "elf-vdso.so.1 too large" 1>&2 | |||||
exit 1 | |||||
fi | |||||
if [ -n "$(${ELFDUMP} -d elf-vdso.so.1 | \ | |||||
${AWK} '/DT_REL.*SZ/{print "RELOCS"}')" ] | |||||
then | |||||
echo "elf-vdso.so.1 contains runtime relocations" 1>&2 | |||||
exit 1 | |||||
fi | |||||
${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \ | |||||
-o elf-vdso.so.o -I. -I"${S}" -include opt_global.h \ | |||||
-DVDSO_NAME=elf_vdso_so_1 -DVDSO_FILE=elf-vdso.so.1 \ | |||||
"${S}"/tools/vdso_wrap.S | |||||
${NM} -D elf-vdso.so.1 | \ | |||||
${AWK} '/__vdso_sigcode/{printf "#define VDSO_SIGCODE_OFFSET 0x%s\n",$1}' \ | |||||
>vdso_offsets.h |
I feel like these should probably just be normal makefile rules; is there a reason they're not?