https://sourceware.org/bugzilla/show_bug.cgi?id=31540
Bug ID: 31540
Summary: objcopy, ELF_SECTION_IN_SEGMENT_1 section to segment
mapping seems wrong
Product: binutils
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: binutils
Assignee: unassigned at sourceware dot org
Reporter: shank.vijay at yandex dot com
Target Milestone: ---
Created attachment 15430
--> https://sourceware.org/bugzilla/attachment.cgi?id=15430&action=edit
contains c file and linker script
This bug was found while building a image for os
How to reproduce :
Take the attached c file and linker-sript and follow through steps
1> clang reprod.c -ffreestanding -c -o reprod.img
2> ld.lld --defsym VMA_START=0xffffffff80100000 --defsym LMA_START=0x4800000 -T
l.ld reprod.img -o reprod.img
3> objcopy --change-section-lma .*-0xffffffff80000000 reprod.img
4> objcopy --adjust-start -0xffffffff80000000 reprod.img
Tool version's:
using clang-17 and binutils 2.40 on x86_64 but issue seems target agnostic.
we get the following issues
First issue we encounter.
objcopy: stq0GBq2: section `.data' can't be allocated in segment 0
LOAD: .tbss .data .bss .sdata
objcopy: stq0GBq2: section `.bss' can't be allocated in segment 0
LOAD: .tbss .data .bss .sdata
second issue the image sizes are overblown
du -sh a.out
34G a.out
Note that the bug seems to only be reproducible with lld
Preliminary observations:
lld
TLS 0x0000000000002058 0xffffffff80100060 (vma) 0xffffffff80100060
(lma)
0x0000000000000000 0x0000000000000004 R 0x4
03 .tbss
Ld Linker
TLS 0x0000000000100098 0xffffffff801000a0 (vma) 0xffffffffc81000a0
(lma)
0x0000000000000000 0x0000000000000004 R 0x4
ELF_SECTION_IN_SEGMENT_1 (include/elf/internal.h) is used to check if section
belongs into a segment (based on VMA) but the heuristics fail because tbss is
considered part of LOAD when it shouldn't be considered as one this becomes an
issue when assigning file offsets assign_file_positions_for_load_sections
(bfd/elf.c) sorts segments based on lma and this is when things seem to go for
a toss.
Previous discussion thread:
https://lists.gnu.org/archive/html/bug-binutils/2024-03/msg00098.html
--
You are receiving this mail because:
You are on the CC list for the bug.