#!/bin/sh1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2021 The FreeBSD Foundation4# All rights reserved.5#6# This software was developed by Konstantin Belousov <[email protected]>7# under sponsorship from the FreeBSD Foundation.8#9# Redistribution and use in source and binary forms, with or without10# modification, are permitted provided that the following conditions11# are met:12# 1. Redistributions of source code must retain the above copyright13# notice, this list of conditions and the following disclaimer.14# 2. Redistributions in binary form must reproduce the above copyright15# notice, this list of conditions and the following disclaimer in the16# documentation and/or other materials provided with the distribution.17#18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28# SUCH DAMAGE.2930set -e3132${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \33-o sigtramp.pico -I. -I"${S}" -include opt_global.h \34"${S}"/amd64/amd64/sigtramp.S3536# We need to make vdso as compact as possible, for it to leave space37# for other things in the shared page. For this, we pack everything38# into single loadable segment.39#40# -z rodynamic is undocumented lld-specific option, seemingly required41# for lld to avoid putting dynamic into dedicated writeable segment,42# despite ldscript placement. It is omitted for ld.bfd, but ldscript43# alone is enough there.44#45if ${LD} --version | ${AWK} '/^GNU ld/{exit 1}' ; then46RODYNAMIC="-z rodynamic"47else48RODYNAMIC=""49fi50${LD} --shared -Bsymbolic -soname="elf-vdso.so.1" \51-T "${S}"/conf/vdso_amd64.ldscript \52--eh-frame-hdr --no-undefined ${RODYNAMIC} -z norelro -nmagic \53--hash-style=sysv --fatal-warnings --strip-all \54-o elf-vdso.so.1 sigtramp.pico5556if [ "$(wc -c elf-vdso.so.1 | ${AWK} '{print $1}')" -gt 2048 ]57then58echo "elf-vdso.so.1 too large" 1>&259exit 160fi6162if [ -n "$(${ELFDUMP} -d elf-vdso.so.1 | \63${AWK} '/DT_REL.*SZ/{print "RELOCS"}')" ]64then65echo "elf-vdso.so.1 contains runtime relocations" 1>&266exit 167fi6869${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \70-o elf-vdso.so.o -I. -I"${S}" -include opt_global.h \71-DVDSO_NAME=elf_vdso_so_1 -DVDSO_FILE=\"elf-vdso.so.1\" \72"${S}"/tools/vdso_wrap.S7374${NM} -D elf-vdso.so.1 | \75${AWK} '/__vdso_sigcode/{printf "#define VDSO_SIGCODE_OFFSET 0x%s\n",$1}' \76>vdso_offsets.h777879