[ELF] Allow misaligned SHT_GNU_verneed
Bazel created interface shared objects (.ifso) may be misaligned. We use llvm::support::detail::packed_endian_specific_integral under the hood which allows reading of misaligned values, so there is not a need to diagnose (in LLD we don't intend to support sophisticated parsing for SHT_GNU_*).
This commit is contained in:
parent
d1f0a76b21
commit
b8a3c618d6
|
@ -1224,14 +1224,12 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
|
|||
ArrayRef<uint8_t> data = CHECK(obj.getSectionContents(sec), this);
|
||||
const uint8_t *verneedBuf = data.begin();
|
||||
for (unsigned i = 0; i != sec->sh_info; ++i) {
|
||||
if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end() ||
|
||||
uintptr_t(verneedBuf) % sizeof(uint32_t) != 0)
|
||||
if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end())
|
||||
fatal(toString(this) + " has an invalid Verneed");
|
||||
auto *vn = reinterpret_cast<const typename ELFT::Verneed *>(verneedBuf);
|
||||
const uint8_t *vernauxBuf = verneedBuf + vn->vn_aux;
|
||||
for (unsigned j = 0; j != vn->vn_cnt; ++j) {
|
||||
if (vernauxBuf + sizeof(typename ELFT::Vernaux) > data.end() ||
|
||||
uintptr_t(vernauxBuf) % sizeof(uint32_t) != 0)
|
||||
if (vernauxBuf + sizeof(typename ELFT::Vernaux) > data.end())
|
||||
fatal(toString(this) + " has an invalid Vernaux");
|
||||
auto *aux = reinterpret_cast<const typename ELFT::Vernaux *>(vernauxBuf);
|
||||
if (aux->vna_name >= this->stringTable.size())
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
## sh_offset(SHT_GNU_verneed) is out of bounds.
|
||||
# RUN: yaml2obj --docnum=1 %s -o %t1.so
|
||||
# RUN: not ld.lld %t.o %t1.so -o /dev/null 2>&1 | FileCheck --check-prefix=SHOFFSET %s
|
||||
# SHOFFSET: error: {{.*}}.so: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x228)
|
||||
# SHOFFSET: error: {{.*}}.so: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x168)
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
|
@ -17,12 +17,14 @@ Sections:
|
|||
- Name: .gnu.version_r
|
||||
Type: SHT_GNU_verneed
|
||||
Flags: [ SHF_ALLOC ]
|
||||
Info: 1
|
||||
ShOffset: 0xFFFFFFFF
|
||||
|
||||
## A Verneed entry is misaligned (not a multiple of 4).
|
||||
## A Verneed entry is misaligned (not a multiple of 4). This may happen
|
||||
## some interface shared objects. We use memcpy to read the fields, so
|
||||
## misalignment isn't a problem and there is no need to diagnose.
|
||||
# RUN: yaml2obj --docnum=2 %s -o %t2.so
|
||||
# RUN: not ld.lld %t.o %t2.so -o /dev/null 2>&1 | FileCheck --check-prefix=VN-MISALIGNED %s
|
||||
# VN-MISALIGNED: {{.*}}.so has an invalid Verneed
|
||||
# RUN: ld.lld %t.o %t2.so -o /dev/null
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
Loading…
Reference in a new issue