[ELF] - Do not produce broken output when amount of sections is > ~65k
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 18 Jul 2018 08:44:38 +0000 (08:44 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 18 Jul 2018 08:44:38 +0000 (08:44 +0000)
commitb9f3ea3e1c7d5e1ddc0f187b3772527f98af3143
tree528c80ef6bda52723d3fc9a0e5b391b08cc801bb
parent9958f620f93d263fcc932b58cdfe9029997d211e
[ELF] - Do not produce broken output when amount of sections is > ~65k

This is a part of ttps://bugs.llvm.org//show_bug.cgi?id=38119

We produce broken ELF header now when the number of output sections is >= SHN_LORESERVE (0xff00).

ELF spec says (http://www.sco.com/developers/gabi/2003-12-17/ch4.eheader.html):

e_shnum:
If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the value zero
and the actual number of section header table entries is contained in the sh_size field of the section header at index 0.
(Otherwise, the sh_size member of the initial entry contains 0.)

e_shstrndx
If the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00), this member has the
value SHN_XINDEX (0xffff) and the actual index of the section name string table section is contained in the sh_link field of
the section header at index 0. (Otherwise, the sh_link member of the initial entry contains 0.)

We did not set these fields correctly earlier. The patch fixes the issue.

Differential revision: https://reviews.llvm.org/D49371

llvm-svn: 337363
lld/ELF/Writer.cpp
lld/test/ELF/relocatable-many-sections.s [new file with mode: 0644]