diff options
author | Jerome Forissier <jerome@forissier.org> | 2019-07-05 14:34:22 +0200 |
---|---|---|
committer | Jérôme Forissier <jerome@forissier.org> | 2019-09-27 16:34:43 +0200 |
commit | 98d863a5c0b27d79c76dbe9fdda73a35b7cf7405 (patch) | |
tree | 69ce40e45841e7ddb7942dbac36e9de75a632ede /scripts | |
parent | 179c8fe8b45d51b7d1337a1ab003a6afb29e78d1 (diff) |
Experimental Clang support
Allows building with Clang with "make COMPILER=clang [other flags...]".
The clang command has to be in the $PATH, as well as the associated
tools (clang-cpp, ld.lld, llvm-ar, llvm-nm, llvm-objcopy and
llvm-readelf).
Tested with Clang built from the master branch of [1] (development
version for 9.0):
mkdir build; cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=~/llvm-install \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM" \
~/llvm-project/llvm
ninja && ninja install
Limitations:
- CFG_CORE_SANITIZE_KADDRESS=y is not supported.
- CFG_WITH_PAGER is supported, but requires that the TEE core be
linked with the GNU linker. The reason is documented in
mk/clang.mk.
Bug:
- ldelf assertion failure in xtest 1019 when CFG_ULIBS_SHARED=y (QEMU)
E/LD: assertion 'maps[map_idx].sz == sz' failed at ldelf/ta_elf.c:1114 in ta_elf_print_mappings()
Prevents ldelf from displaying the TA mappings on abort or panic, but
does not seem to cause any other problem.
Link: [1] https://github.com/llvm/llvm-project/commits/8351c327647
Signed-off-by: Jerome Forissier <jerome@forissier.org>
Tested-by: Jerome Forissier <jerome@forissier.org> (QEMU pager/no pager)
Tested-by: Jerome Forissier <jerome@forissier.org> (QEMUv8, pager/no pager)
Tested-by: Jerome Forissier <jerome@forissier.org> (HiKey960, 32/64, GP)
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/llvm-objcopy-wrapper | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/scripts/llvm-objcopy-wrapper b/scripts/llvm-objcopy-wrapper new file mode 100755 index 00000000..fb67a987 --- /dev/null +++ b/scripts/llvm-objcopy-wrapper @@ -0,0 +1,88 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019, Linaro Limited +# +# This is a wrapper script to llvm-objcopy to add support for: +# - The --pad-to argument +# - Regular expressions in --only-section= and --remove-section +# - Creating empty output files when no section match +# - Allowing removal of sections that are referenced by some other sections +# by default (--allow-broken-links). +# +# Depends on llvm-readelf. + +args=("--allow-broken-links") # llvm-objcopy >= 9.0 +only_section_re=() +remove_section_re=() +for arg in "$@"; do + if [ "$pad_found" ]; then + pad_addr="$arg" + pad_found= + continue + fi + case "$arg" in + --pad-to) + pad_found=1 + continue + ;; + --only-section=*) + re=$(echo "$arg" | sed s/--only-section=//) + only_section_re+=("$re") + continue + ;; + --remove-section=*) + re=$(echo "$arg" | sed s/--remove-section=//) + remove_section_re+=("$re") + continue + ;; + esac + args+=("$arg") +done + +in="${@: -2:1}" +out="${@: -1:1}" +if [ ! -e "$in" ]; then + in=$out # That is good enough for our use cases +fi + +if [ '${only_section_re[@]}''${remove_section_re[@]}' ]; then + sections=$(llvm-readelf -sections $in | grep ' *\[ *[0-9]*] [^ ]' | sed 's/ *\[ *[0-9]*] \(.[^ ]*\).*/\1/') + for s in $sections; do + for re in "${only_section_re[@]}"; do + if [ "$(echo $s | grep -- $re)" != "" ]; then + args+=("--only-section=$s") + break + fi + done + for re in "${remove_section_re[@]}"; do + if [ "$(echo $s | grep -- $re)" != "" ]; then + args+=("--remove-section=$s") + break + fi + done + done +fi + +pad_sz=0 +if [ "$pad_addr" ]; then + + # Find address and size of last PROGBITS section in input file + addr_sz=$(llvm-readelf -sections $in | grep PROGBITS | sed 's/.*PROGBITS *\([^ ]*\) [^ ]* \([^ ]*\).*/\1 \2/' | sort -n | tail -1) + read addr sz <<< "$addr_sz" + + # Now figure out the size of the padding. Can be 0. + pad_sz=$(($pad_addr - 0x$addr - 0x$sz)) +fi + +# Run llvm-objcopy without "--pad-to <addr>" and with expanded +# --only-section/--remove-section +if [ "$VV" = 1 ]; then + echo Running: llvm-objcopy "${args[@]}" +fi +llvm-objcopy "${args[@]}" || exit $? + +# Pad with zeroes if necessary +if [ $pad_sz -gt 0 ]; then + truncate -s +$pad_sz $out +fi |