blob: b239dab672b181a7c28c24e9cc05c11677762169 [file]
#!/bin/bash
#
# Copyright 2022 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
set -e -o pipefail
if [[ $# -ne 3 ]]; then
echo >&2 "Usage: $0 RSPFILE OUTPUT DEPFILE"
exit 2
fi
readonly RSPFILE="$1" # Name of link_output_rspfile() output.
readonly OUTPUT="$2" # .S (.inc) file to write.
readonly DEPFILE="$3" # depfile to write.
readonly LINK_OUTPUT="$(<"${RSPFILE}")"
readonly BUILD_ID_FILE="${LINK_OUTPUT}.build-id.stamp"
readonly BUILD_ID="$(<"$BUILD_ID_FILE")"
echo > "$OUTPUT.new" "\
// Generated by $0 $*. DO NOT EDIT!
// The linker interprets this magic section name and generates a PT_INTERP
// segment pointing at it. It contains the NUL-terminated interpreter
// name. In kernel-land, we use this for physboot-compatible ELF objects
// to identify the particular physboot binary they were built to go with by
// its ELF build ID as a text string of lowercase hexadecimal.
.section .interp, \"aR\", %progbits
.balign 1
.asciz \"${BUILD_ID}\""
if [[ -r "$OUTPUT" && "$(<"$OUTPUT.new")" = "$(<"$OUTPUT")" ]]; then
# Leave $OUTPUT untouched since it would be identical and so does not
# necessarily need to be recompiled.
rm -f "$OUTPUT.new"
else
mv -f "$OUTPUT.new" "$OUTPUT"
fi
echo > "$DEPFILE" "\
${OUTPUT}: ${RSPFILE} ${BUILD_ID_FILE}"
exit 0