From 4589fdfad43ec6ddf0c05f58d32d83ee9a6d5f01 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Mon, 25 Jul 2022 12:55:26 +0200 Subject: [PATCH] Fix netbsd elf problem The dynamic linker on netbsd can only handle 2 PT_LOAD sections. --- tccelf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tccelf.c b/tccelf.c index 532785f3..4aad175e 100644 --- a/tccelf.c +++ b/tccelf.c @@ -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; }