Attempt to fix ubsan.
authorRui Ueyama <ruiu@google.com>
Tue, 9 Oct 2018 21:41:53 +0000 (21:41 +0000)
committerRui Ueyama <ruiu@google.com>
Tue, 9 Oct 2018 21:41:53 +0000 (21:41 +0000)
commit2b53b4bea611824a933123780357b5a2cbe2ed0f
tree71930dec4687c3b669f24e445d7caeedff10edf4
parente9ca7ea3e5c0f3e155fc7b47cb9068a2f12cae6a
Attempt to fix ubsan.

Previously, we cast a pointer to Elf{32,64}_Chdr like this

  auto *Hdr = reinterpret_cast<const ELF64_Chdr>(Ptr);

and read from its members like this

  read32(&Hdr->ch_size);

I was thinking that this does not violate alignment requirement,
since &Hdr->ch_size doesn't really access memory, but seems like
it is a violation in terms of C++ spec (?)

In this patch, I use a different struct that allows unaligned access.

llvm-svn: 344083
lld/ELF/InputSection.cpp