From: Greg Ungerer Date: Wed, 30 Oct 2019 06:08:19 +0000 (+1000) Subject: elf2flt: fix relocations for read-only data X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=73325b7f209e0f68887333385184af275531427d;p=elf2flt.git elf2flt: fix relocations for read-only data Readonly data sections are mapped into the "text" section in the elf2flt.ld linker script. The relocation generation code is not handling that case properly though, and is actually mapping any data section type into the "data" section of the target binary. This problem case has been detected with elf2flt core dumping when used with binutils-2.33.1 (on ARM architecture targets). See thread at: https://sourceware.org/ml/binutils/2019-10/msg00132.html Signed-off-by: Greg Ungerer --- diff --git a/elf2flt.c b/elf2flt.c index 67f720a..8973cef 100644 --- a/elf2flt.c +++ b/elf2flt.c @@ -418,10 +418,12 @@ output_relocs ( // continue; /* - * Only relocate things in the data sections if we are PIC/GOT. - * otherwise do text as well + * Only relocate things in the writable data sections if we are PIC/GOT. + * Otherwise do text (and read only data) as well. */ - if ((!pic_with_got || ALWAYS_RELOC_TEXT) && (a->flags & SEC_CODE)) + if ((!pic_with_got || ALWAYS_RELOC_TEXT) && + ((a->flags & SEC_CODE) || + ((a->flags & (SEC_DATA | SEC_READONLY)) == (SEC_DATA | SEC_READONLY)))) sectionp = text + (a->vma - text_vma); else if (a->flags & SEC_DATA) sectionp = data + (a->vma - data_vma);