Skip to content

Commit

Permalink
Allow a newline or a tab at the begining of a linker script
Browse files Browse the repository at this point in the history
Previously, the first four byte must have been "printable" bytes,
which exclude newlines or tabs.
  • Loading branch information
rui314 committed Apr 29, 2024
1 parent cbbe23a commit ea054cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions common/filetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ enum class FileType {

template <typename MappedFile>
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 <typename E, typename Context, typename MappedFile>
Expand Down
15 changes: 15 additions & 0 deletions test/elf/linker-script6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
. $(dirname $0)/common.inc

mkdir -p $t/foo

cat <<EOF | $CC -o $t/foo/a.o -c -xc -
int main() {}
EOF

cat <<EOF > $t/foo/b.script
INPUT(a.o)
EOF

$CC -B. -o $t/exe $t/foo/b.script

0 comments on commit ea054cc

Please sign in to comment.