mirror of
https://github.com/rui314/mold.git
synced 2024-10-26 13:10:46 +03:00
Handle sections with an unknown section type as errors
Fixes https://github.com/rui314/mold/issues/1215
This commit is contained in:
parent
c4b69a1077
commit
d21207cc79
@ -81,15 +81,19 @@ enum : u32 {
|
||||
SHT_GROUP = 17,
|
||||
SHT_SYMTAB_SHNDX = 18,
|
||||
SHT_RELR = 19,
|
||||
SHT_LOOS = 0x60000000,
|
||||
SHT_LLVM_ADDRSIG = 0x6fff4c03,
|
||||
SHT_GNU_HASH = 0x6ffffff6,
|
||||
SHT_GNU_VERDEF = 0x6ffffffd,
|
||||
SHT_GNU_VERNEED = 0x6ffffffe,
|
||||
SHT_GNU_VERSYM = 0x6fffffff,
|
||||
SHT_HIOS = 0x6fffffff,
|
||||
SHT_X86_64_UNWIND = 0x70000001,
|
||||
SHT_ARM_EXIDX = 0x70000001,
|
||||
SHT_ARM_ATTRIBUTES = 0x70000003,
|
||||
SHT_RISCV_ATTRIBUTES = 0x70000003,
|
||||
SHT_LOUSER = 0x80000000,
|
||||
SHT_HIUSER = 0xffffffff,
|
||||
};
|
||||
|
||||
enum : u32 {
|
||||
@ -100,6 +104,7 @@ enum : u32 {
|
||||
SHF_STRINGS = 0x20,
|
||||
SHF_INFO_LINK = 0x40,
|
||||
SHF_LINK_ORDER = 0x80,
|
||||
SHF_OS_NONCONFORMING = 0x100,
|
||||
SHF_GROUP = 0x200,
|
||||
SHF_TLS = 0x400,
|
||||
SHF_COMPRESSED = 0x800,
|
||||
|
@ -233,6 +233,32 @@ static void read_riscv_attributes(Context<E> &ctx, ObjectFile<E> &file,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
static bool is_known_section_type(const ElfShdr<E> &shdr) {
|
||||
u32 ty = shdr.sh_type;
|
||||
u32 flags = shdr.sh_flags;
|
||||
|
||||
if (ty == SHT_PROGBITS ||
|
||||
ty == SHT_NOTE ||
|
||||
ty == SHT_NOBITS ||
|
||||
ty == SHT_INIT_ARRAY ||
|
||||
ty == SHT_FINI_ARRAY ||
|
||||
ty == SHT_PREINIT_ARRAY)
|
||||
return true;
|
||||
|
||||
if (SHT_LOUSER <= ty && ty <= SHT_HIUSER && !(flags & SHF_ALLOC))
|
||||
return true;
|
||||
if (SHT_LOOS <= ty && ty <= SHT_HIOS && !(flags & SHF_OS_NONCONFORMING))
|
||||
return true;
|
||||
if (is_x86<E> && ty == SHT_X86_64_UNWIND)
|
||||
return true;
|
||||
if (is_arm32<E> && (ty == SHT_ARM_EXIDX || ty == SHT_ARM_ATTRIBUTES))
|
||||
return true;
|
||||
if (is_riscv<E> && ty == SHT_RISCV_ATTRIBUTES)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void ObjectFile<E>::initialize_sections(Context<E> &ctx) {
|
||||
// Read sections
|
||||
@ -305,6 +331,10 @@ void ObjectFile<E>::initialize_sections(Context<E> &ctx) {
|
||||
case SHT_NULL:
|
||||
break;
|
||||
default:
|
||||
if (!is_known_section_type(shdr))
|
||||
Fatal(ctx) << *this << ": " << name << ": unsupported section type: 0x"
|
||||
<< std::hex << (u32)shdr.sh_type;
|
||||
|
||||
// .note.GNU-stack section controls executable-ness of the stack
|
||||
// area in GNU linkers. We ignore that section because silently
|
||||
// making the stack area executable is too dangerous. Tell our
|
||||
|
12
test/elf/unkown-section-type.sh
Executable file
12
test/elf/unkown-section-type.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
. $(dirname $0)/common.inc
|
||||
|
||||
# ARM assembler does not seem to accept a hexnum after the atsign
|
||||
[ $MACHINE = arm ] && skip
|
||||
|
||||
cat <<EOF | $CC -o $t/a.o -c -xassembler -
|
||||
.section .my_section,"a",@0x80000000
|
||||
EOF
|
||||
|
||||
! $CC -B. -o $t/exe $t/a.o >& $t/log1
|
||||
grep -q 'unsupported section type: 0x80000000' $t/log1
|
Loading…
Reference in New Issue
Block a user