This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
ia32 linux: problems with linker / strip / BFD
- From: Etienne Lorrain <etienne_lorrain at yahoo dot fr>
- To: binutils at sourceware dot org
- Date: Wed, 7 Feb 2007 23:18:22 +0100 (CET)
- Subject: ia32 linux: problems with linker / strip / BFD
Hello,
Just two points about program headers/strip and BFD on ia32.
I just want to report that, I do not know if it shall be considered as a bug,
as bad use, as undocumented feature - just to make someone aware by searching
the list if no action is taken:
Lets compile some Linux kernel:
[etienne@localhost tmp]$ tar xjf ../linux2/linux-2.6.20.tar.bz2
[etienne@localhost tmp]$ cd linux-2.6.20
[etienne@localhost linux-2.6.20]$ cp ../../linux2/linux-2.6.20-gujin/.config .
[etienne@localhost linux-2.6.20]$ make oldconfig > log
[etienne@localhost linux-2.6.20]$ make vmlinux >> log
... few warnings ...
[etienne@localhost linux-2.6.20]$ readelf -l vmlinux
Elf file type is EXEC (Executable file)
Entry point 0x100000
There are 3 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xc0100000 0x00100000 0x3995e0 0x3995e0 R E 0x1000
LOAD 0x39b000 0xc049a000 0x0049a000 0x75085 0xaf000 RWE 0x1000
NOTE 0x000000 0x00000000 0x00000000 0x00000 0x00000 R 0x4
Section to Segment mapping:
Segment Sections...
00 .text __ex_table .rodata .pci_fixup __param
01 .data .data_nosave .data.page_aligned .data.cacheline_aligned .data.read_mostly
.data.init_task .init.text .init.data .init.setup .initcall.init .con_initcall.init
.security_initcall.init .altinstructions .altinstr_replacement .exit.text .init.ramfs
.bss
02
[etienne@localhost linux-2.6.20]$
OK, everything is fine. The ld script affects manually the program header by:
/* arch/i386/kernel/vmlinux.lds.S */
PHDRS {
text PT_LOAD FLAGS(5); /* R_E */
data PT_LOAD FLAGS(7); /* RWE */
note PT_NOTE FLAGS(4); /* R__ */
}
And the text section goes to the :text program header, it is linked at a fixed address.
.text : AT(ADDR(.text) - LOAD_OFFSET) {
...
} :text = 0x9090
Now I want to create another text section - I was thinking that a new program header
would be added or an error message because I create it a another address, using
the patch at sourceforge at:
http://sourceforge.net/project/showfiles.php?group_id=15465&package_id=174813&release_id=482035
The important extract is:
SECTIONS
{
.realmode 0 : AT (ADDR(.bss) + SIZEOF(.bss) - LOAD_OFFSET) {
... all my sections ...
} :text = 0x9090
. = 0xc0000000 ; /* or more */
.text : AT(ADDR(.text) - LOAD_OFFSET) {
... original part ...
} :text = 0x9090
[etienne@localhost linux-2.6.20]$ patch -p1 < ../../linux/gujin-patch-2.6.20-rc5
patching file arch/i386/Kconfig
patching file arch/i386/kernel/Makefile
patching file arch/i386/kernel/realmode.c
patching file arch/i386/kernel/setup.c
patching file arch/i386/kernel/vmlinux.lds.S
patching file arch/i386/Makefile
patching file include/asm-i386/realmode.h
patching file Makefile
patching file scripts/gzcopy.c
patching file scripts/gzparam.c
[etienne@localhost linux-2.6.20]$ make linux-2.6.20.kgz > log
But nothing change and I do not get any warning or error for a section
containing code not linked to a program header:
[etienne@localhost linux-2.6.20]$ readelf -l vmlinux
Elf file type is EXEC (Executable file)
Entry point 0x100000
There are 3 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xc0100000 0x00100000 0x44a830 0x44a830 R E 0x1000
LOAD 0x44c000 0xc049a000 0x0049a000 0x75085 0xaf000 RWE 0x1000
NOTE 0x000000 0x00000000 0x00000000 0x00000 0x00000 R 0x4
Section to Segment mapping:
Segment Sections...
00 .bss .text __ex_table .rodata .pci_fixup __param .data .data_nosave
.data.page_aligned .data.cacheline_aligned .data.read_mostly .data.init_task .init.text
.init.data .init.setup .initcall.init .con_initcall.init .security_initcall.init
.altinstructions .altinstr_replacement .exit.text .init.ramfs
01 .bss .data .data_nosave .data.page_aligned .data.cacheline_aligned
.data.read_mostly .data.init_task .init.text .init.data .init.setup .initcall.init
.con_initcall.init .security_initcall.init .altinstructions .altinstr_replacement
.exit.text .init.ramfs
02
[etienne@localhost linux-2.6.20]$
And there is something wrong once using strip from this file:
[etienne@localhost linux-2.6.20]$ objcopy -S vmlinux vmlinux.stripped
BFD: vmlinux.stripped: warning: allocated section `.realmode' not in segment
[etienne@localhost linux-2.6.20]$ readelf -l vmlinux.stripped
Elf file type is EXEC (Executable file)
Entry point 0x100000
There are 3 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0xc0100000 0x00100000 0x40f085 0x449000 R E 0x1000
LOAD 0x411000 0xc049a000 0x0049a000 0x75085 0xaf000 RWE 0x1000
NOTE 0x000000 0x00000000 0x00000000 0x00000 0x00000 R 0x4
Section to Segment mapping:
Segment Sections...
00 .bss .text __ex_table .rodata .pci_fixup __param .data .data_nosave
.data.page_aligned .data.cacheline_aligned .data.read_mostly .data.init_task .init.text
.init.data .init.setup .initcall.init .con_initcall.init .security_initcall.init
.altinstructions .altinstr_replacement .exit.text .init.ramfs
01 .bss .data .data_nosave .data.page_aligned .data.cacheline_aligned
.data.read_mostly .data.init_task .init.text .init.data .init.setup .initcall.init
.con_initcall.init .security_initcall.init .altinstructions .altinstr_replacement
.exit.text .init.ramfs
02
[etienne@localhost linux-2.6.20]$
Note that the first program header MemSiz overlap the second program header:
0x00100000 + 0x449000 > 0x0049a000
And the two FileSiz are not aligned so the memset at PhysAddr+FileSiz is done
at an unaligned address so will be slow.
I do not know what should be the behaviour, just something seems wrong.
Something completely different, when using the linux patch I posted on LKM, where
a new program header is created for this section, and is removed if i want to get
rid of the section .realmode completely because I want to generate the old target,
you can ask me the question:
[etienne@localhost linux-2.6.20-gujin]$ objcopy -R .note -R .comment -R .realmode -S
vmlinux vmlinux.tmp
BFD: vmlinux: warning: Empty loadable segment detected, is this intentional ?
[etienne@localhost linux-2.6.20-gujin]$
My answer is that it is not needed to keep this empty loadable segment, you can strip
it.
I do not care of the warning because that command is used "-O binary" by Linux Makefile
and does not produce the warning.
Thanks,
Etienne.
___________________________________________________________________________
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com