Fix netbsd elf problem

The dynamic linker on netbsd can only handle 2 PT_LOAD sections.
This commit is contained in:
herman ten brugge 2022-07-25 12:55:26 +02:00
parent 09808f327f
commit 4589fdfad4

View File

@ -1951,8 +1951,14 @@ static int sort_sections(TCCState *s1, int *sec_order, Section *interp)
f = 0;
if (k < 0x700) {
f = s->sh_flags & (SHF_ALLOC|SHF_WRITE|SHF_EXECINSTR|SHF_TLS);
#if TARGETOS_NetBSD
/* NetBSD only supports 2 PT_LOAD sections.
See: https://blog.netbsd.org/tnf/entry/the_first_report_on_lld */
if ((f & SHF_WRITE) == 0) f |= SHF_EXECINSTR;
#else
if ((k & 0xfff0) == 0x240) /* RELRO sections */
f |= 1<<4;
#endif
if (f != f0) /* start new header when flags changed or relro */
f0 = f, ++n, f |= 1<<8;
}