xref: /freebsd/sys/tools/amd64_vdso.sh (revision 3b2cf9381ef86847603c3c94811f638660c417ae)
1ab4524b3SKonstantin Belousov#!/bin/sh
24d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
3ab4524b3SKonstantin Belousov#
4ab4524b3SKonstantin Belousov# Copyright (c) 2021 The FreeBSD Foundation
5ab4524b3SKonstantin Belousov# All rights reserved.
6ab4524b3SKonstantin Belousov#
7ab4524b3SKonstantin Belousov# This software was developed by Konstantin Belousov <kib@FreeBSD.org>
8ab4524b3SKonstantin Belousov# under sponsorship from the FreeBSD Foundation.
9ab4524b3SKonstantin Belousov#
10ab4524b3SKonstantin Belousov# Redistribution and use in source and binary forms, with or without
11ab4524b3SKonstantin Belousov# modification, are permitted provided that the following conditions
12ab4524b3SKonstantin Belousov# are met:
13ab4524b3SKonstantin Belousov# 1. Redistributions of source code must retain the above copyright
14ab4524b3SKonstantin Belousov#    notice, this list of conditions and the following disclaimer.
15ab4524b3SKonstantin Belousov# 2. Redistributions in binary form must reproduce the above copyright
16ab4524b3SKonstantin Belousov#    notice, this list of conditions and the following disclaimer in the
17ab4524b3SKonstantin Belousov#    documentation and/or other materials provided with the distribution.
18ab4524b3SKonstantin Belousov#
19ab4524b3SKonstantin Belousov# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20ab4524b3SKonstantin Belousov# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ab4524b3SKonstantin Belousov# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ab4524b3SKonstantin Belousov# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23ab4524b3SKonstantin Belousov# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24ab4524b3SKonstantin Belousov# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25ab4524b3SKonstantin Belousov# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26ab4524b3SKonstantin Belousov# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27ab4524b3SKonstantin Belousov# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28ab4524b3SKonstantin Belousov# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29ab4524b3SKonstantin Belousov# SUCH DAMAGE.
30ab4524b3SKonstantin Belousov
31ab4524b3SKonstantin Belousovset -e
32ab4524b3SKonstantin Belousov
33ab4524b3SKonstantin Belousov${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \
34ab4524b3SKonstantin Belousov   -o sigtramp.pico -I. -I"${S}" -include opt_global.h \
35ab4524b3SKonstantin Belousov   "${S}"/amd64/amd64/sigtramp.S
36ab4524b3SKonstantin Belousov
37ab4524b3SKonstantin Belousov# We need to make vdso as compact as possible, for it to leave space
38ab4524b3SKonstantin Belousov# for other things in the shared page.  For this, we pack everything
39ab4524b3SKonstantin Belousov# into single loadable segment.
40ab4524b3SKonstantin Belousov#
41ab4524b3SKonstantin Belousov# -z rodynamic is undocumented lld-specific option, seemingly required
42ab4524b3SKonstantin Belousov# for lld to avoid putting dynamic into dedicated writeable segment,
43*3b2cf938SKonstantin Belousov# despite ldscript placement.  It is omitted for ld.bfd, but ldscript
44ab4524b3SKonstantin Belousov# alone is enough there.
45ab4524b3SKonstantin Belousov#
46*3b2cf938SKonstantin Belousovif ${LD} --version | ${AWK} '/^GNU ld/{exit 1}' ; then
47*3b2cf938SKonstantin Belousov    RODYNAMIC="-z rodynamic"
48*3b2cf938SKonstantin Belousovelse
49*3b2cf938SKonstantin Belousov    RODYNAMIC=""
50*3b2cf938SKonstantin Belousovfi
51ab4524b3SKonstantin Belousov${LD} --shared -Bsymbolic -soname="elf-vdso.so.1" \
52ab4524b3SKonstantin Belousov   -T "${S}"/conf/vdso_amd64.ldscript \
53*3b2cf938SKonstantin Belousov   --eh-frame-hdr --no-undefined ${RODYNAMIC} -z norelro -nmagic \
54ab4524b3SKonstantin Belousov   --hash-style=sysv --fatal-warnings --strip-all \
55ab4524b3SKonstantin Belousov   -o elf-vdso.so.1 sigtramp.pico
56ab4524b3SKonstantin Belousov
57b0e0b4e7SKonstantin Belousovif [ "$(wc -c elf-vdso.so.1 | ${AWK} '{print $1}')" -gt 2048 ]
58b0e0b4e7SKonstantin Belousovthen
59b0e0b4e7SKonstantin Belousov    echo "elf-vdso.so.1 too large" 1>&2
60b0e0b4e7SKonstantin Belousov    exit 1
61b0e0b4e7SKonstantin Belousovfi
62b0e0b4e7SKonstantin Belousov
63d49b75d0SKonstantin Belousovif [ -n "$(${ELFDUMP} -d elf-vdso.so.1 | \
64d49b75d0SKonstantin Belousov  ${AWK} '/DT_REL.*SZ/{print "RELOCS"}')" ]
65d49b75d0SKonstantin Belousovthen
66d49b75d0SKonstantin Belousov    echo "elf-vdso.so.1 contains runtime relocations" 1>&2
67d49b75d0SKonstantin Belousov    exit 1
68d49b75d0SKonstantin Belousovfi
69d49b75d0SKonstantin Belousov
70169b368aSJessica Clarke${CC} ${DEBUG} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \
71ab4524b3SKonstantin Belousov   -o elf-vdso.so.o -I. -I"${S}" -include opt_global.h \
728a6ab0f7SJessica Clarke   -DVDSO_NAME=elf_vdso_so_1 -DVDSO_FILE=\"elf-vdso.so.1\" \
73ab4524b3SKonstantin Belousov   "${S}"/tools/vdso_wrap.S
74ab4524b3SKonstantin Belousov
75ab4524b3SKonstantin Belousov${NM} -D elf-vdso.so.1 | \
765b8918faSKonstantin Belousov   ${AWK} '/__vdso_sigcode/{printf "#define VDSO_SIGCODE_OFFSET 0x%s\n",$1}' \
77ab4524b3SKonstantin Belousov   >vdso_offsets.h
78