This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Possible bug in ld with NOLOAD sections.
- From: Tony Breeds <tony at bakeyournoodle dot com>
- To: binutils at sourceware dot org
- Date: Thu, 19 Nov 2009 09:40:14 +1100
- Subject: Possible bug in ld with NOLOAD sections.
Hello All,
Please forgive me If I ramble a little or if I should have reported
this elsewhere I wanted to be sure it was a bug rather then a silly mistake on
my part.
A little background.
I'm trying to include a section in an ELF executable but NOT have that section
covered by the PT_LOAD. Looking at the binutils docs (and if I have understood
the correctly) I should be able to mark that section 'NOLOAD' to achieve that
behaviour. However, it seems when I do that the section I'm interested in is
completely omitted from the linked ELF.
I've included a Makefile that demonstrates what I'm doing.
It creates a 4k "blob" of data in the ".blob" section (blob.o), and then links
that into main (without NOLOAD), and also into main-noload. As you can see
from the ls output below main-noload is substantially smaller than main.
The blob.test (and blob.test-noload) are the results of trying to:
objcopy -O binary -j .blob main (and main-noload)
I've tried the with a few distro binutils and a CVS checkout and I get the same
behaviour.
---
ls -l lds lds-noload blob.o main main-noload blob.test blob.test-noload
-rw-rw-r--. 1 tony tony 5528 2009-11-18 14:27 blob.o
-rwxrwxr-x. 1 tony tony 4096 2009-11-18 14:27 blob.test
-rwxrwxr-x. 1 tony tony 0 2009-11-18 14:27 blob.test-noload
-rw-rw-r--. 1 tony tony 6931 2009-11-18 14:27 lds
-rw-rw-r--. 1 tony tony 6940 2009-11-18 14:27 lds-noload
-rwxrwxr-x. 1 tony tony 6120 2009-11-18 14:27 main
-rwxrwxr-x. 1 tony tony 2012 2009-11-18 14:27 main-noload
---
So:
1) Am I interpreting what NOLOAD is supposed to do correctly?
2) Have I done something silly or should I open a bugzilla?
3) What else can I do to help?
Yours Tony
-----
SHELL = /bin/bash
BUILDROOT = /home/tony/projects/binutils/obj
CC = gcc
CFLAGS = -Wall -Werror -Wextra -O0 -g
LD = $(BUILDROOT)/ld/ld-new
LD = ld
LDFLAGS =
all: lds lds-noload blob.o main main-noload blob.test blob.test-noload
ls -l $^
main.c: Makefile
echo 'int main(void) { return 0; }' > $@
blob.c: Makefile
echo 'static unsigned char blob[4096] __attribute__((section(".blob"), used)) = { [0 ... 4095] = 0xff };' > $@
main: blob.o main.o
$(LD) -T lds -o $@ $^
lds: Makefile
$(LD) --verbose | \
sed -e '0,/===/ d ; /===/ d' \
-e '/__bss_start/ i .blob : { *(.blob) }' >$@
blob.test: main
objcopy -O binary -j .blob $< $@
main-noload: blob.o main.o
$(LD) -T lds-noload -o $@ $^
lds-noload: Makefile
$(LD) --verbose | \
sed -e '0,/===/ d ; /===/ d' \
-e '/__bss_start/ i .blob (NOLOAD) : { *(.blob) }' >$@
blob.test-noload: main-noload
objcopy -O binary -j .blob $< $@
.PHONY: clean
clean:
-$(RM) main* empty* blob* lds*
-----