From ea054ccced2dce076fb468bc64bca969b3d8d056 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 29 Apr 2024 14:42:13 +0900 Subject: [PATCH] Allow a newline or a tab at the begining of a linker script Previously, the first four byte must have been "printable" bytes, which exclude newlines or tabs. --- common/filetype.h | 8 ++++++-- test/elf/linker-script6.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/elf/linker-script6.sh diff --git a/common/filetype.h b/common/filetype.h index 3d1d520a94..b2c46578ae 100644 --- a/common/filetype.h +++ b/common/filetype.h @@ -25,9 +25,13 @@ enum class FileType { template bool is_text_file(MappedFile *mf) { + auto istext = [](char c) { + return isprint(c) || c == '\n' || c == '\t'; + }; + u8 *data = mf->data; - return mf->size >= 4 && isprint(data[0]) && isprint(data[1]) && - isprint(data[2]) && isprint(data[3]); + return mf->size >= 4 && istext(data[0]) && istext(data[1]) && + istext(data[2]) && istext(data[3]); } template diff --git a/test/elf/linker-script6.sh b/test/elf/linker-script6.sh new file mode 100644 index 0000000000..e767f33ec5 --- /dev/null +++ b/test/elf/linker-script6.sh @@ -0,0 +1,15 @@ +#!/bin/bash +. $(dirname $0)/common.inc + +mkdir -p $t/foo + +cat < $t/foo/b.script + +INPUT(a.o) +EOF + +$CC -B. -o $t/exe $t/foo/b.script