#!/bin/sh # Host objcopy lacks the riscv backend. Force the generic elf64-little # reader so it can parse the input, then restore e_machine/e_flags in # the output (which objcopy writes as EM_NONE) from the input file. # # Kernel objcopy invocations are: objcopy [FLAGS] INPUT OUTPUT # (cmd_objcopy in scripts/Makefile.lib). The last two args are always # the in/out files. in="" out="" for a; do case "$a" in -*) ;; *) in=$out; out=$a ;; esac done /usr/bin/objcopy -I elf64-little "$@" || exit $? # If output is ELF, restore e_machine (0x12, 2 bytes) and e_flags # (0x30, 4 bytes) from the input so lld recognises it as riscv. if [ -n "$in" ] && [ -f "$in" ] && [ -f "$out" ] && \ [ "$(head -c4 "$out" 2>/dev/null)" = "$(printf '\177ELF')" ]; then dd if="$in" of="$out" bs=1 skip=18 seek=18 count=2 conv=notrunc 2>/dev/null dd if="$in" of="$out" bs=1 skip=48 seek=48 count=4 conv=notrunc 2>/dev/null fi exit 0