This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RELASZ is set to 0 on x86_64 when developing EFI applications with gnu-efi
- From: éæ <yanmiaobest at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 6 Jun 2014 15:21:46 +0800
- Subject: RELASZ is set to 0 on x86_64 when developing EFI applications with gnu-efi
- Authentication-results: sourceware.org; auth=none
Hi Experts,
I am developing EFI applications using gnu-efi library and I
need to use some of the existing code base which groups initialization
functions together in a special section.
The gnu-efi library uses the symbol _DYNAMIC to locate the
relocation section and does fixups before calling main. Without the
special section for init functions, there is only a '.rela' section
pointed by _DYMAMIC and everything works fine. But after I modified
the default linker script, the produced ELF image contains 2
relocation sections:
--------------------------------------------------------------------------------------------------------------
Relocation section '.rela.dyn' at offset 0x23850 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000027de0 000000000008 R_X86_64_RELATIVE 000000000000b7d0
Relocation section '.rela' at offset 0x37000 contains 148 entries:
Offset Info Type Sym. Value Sym. Name + Addend
0000000175a0 000000000008 R_X86_64_RELATIVE 0000000000015001
0000000175a8 000000000008 R_X86_64_RELATIVE 0000000000015121
0000000175b0 000000000008 R_X86_64_RELATIVE 0000000000015241
--------------------------------------------------------------------------------------------------------------
And now _DYNAMIC points to .rela.dyn, and the binary crashes during
relocation process.
I tried to squash the .rela.* sections into one in the linker script,
and got the "RELASZ is 0" problem. So what's the correct way to do
this ? (I couldn't find gnu-efi mailing list, so I send it here, sorry
if it's not the right list )
-------------------------------------------------------------------------------------------------------------
LF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x10e60
Start of program headers: 64 (bytes into file)
Start of section headers: 246528 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 2
Size of section headers: 64 (bytes)
Number of section headers: 12
Section header string table index: 11
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000008000 00018000
000000000000b858 0000000000000000 AX 0 0 16
[ 2] .hash HASH 0000000000000000 00010000
0000000000000a54 0000000000000004 A 7 0 8
[ 3] .eh_frame PROGBITS 0000000000001000 00011000
0000000000003150 0000000000000000 A 0 0 8
[ 4] .reloc PROGBITS 0000000000014000 00024000
000000000000000a 0000000000000000 A 0 0 1
[ 5] .data PROGBITS 0000000000015000 00025000
0000000000010a98 0000000000000008 WA 0 0 32
[ 6] .dynamic DYNAMIC 0000000000026000 00036000
0000000000000100 0000000000000010 WA 9 0 8
[ 7] .dynsym DYNSYM 0000000000028000 00038000
0000000000002520 0000000000000018 A 9 2 8
[ 8] .rela RELA 0000000000027000 00037000
0000000000000df8 0000000000000018 A 7 0 8
[ 9] .dynstr STRTAB 000000000002b000 0003b000
0000000000001278 0000000000000000 A 0 0 1
[10] .comment PROGBITS 0000000000000000 0003c278
000000000000002f 0000000000000001 MS 0 0 1
[11] .shstrtab STRTAB 0000000000000000 0003c2a7
0000000000000056 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000010000 0x0000000000000000 0x0000000000000000
0x000000000002c278 0x000000000002c278 RWE 10000
DYNAMIC 0x0000000000036000 0x0000000000026000 0x0000000000026000
0x0000000000000100 0x0000000000000100 RW 8
Section to Segment mapping:
Segment Sections...
00 .text .hash .eh_frame .reloc .data .dynamic .dynsym .rela .dynstr
01 .dynamic
Dynamic section at offset 0x36000 contains 11 entries:
Tag Type Name/Value
0x0000000000000010 (SYMBOLIC) 0x0
0x0000000000000004 (HASH) 0x0
0x0000000000000005 (STRTAB) 0x2b000
0x0000000000000006 (SYMTAB) 0x28000
0x000000000000000a (STRSZ) 4728 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000007 (RELA) 0x27000
0x0000000000000008 (RELASZ) 0 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x0000000000000016 (TEXTREL) 0x0
0x0000000000000000 (NULL) 0x0
Relocation section '.rela' at offset 0x37000 contains 149 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000017578 000000000008 R_X86_64_RELATIVE 000000000000e580
000000017580 000000000008 R_X86_64_RELATIVE 000000000000bee0
[...]
------------------------------------------------------------------------------------------------------------
Here is my linker scripts (from gnu-efi)
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SECTIONS
{
. = 0;
ImageBase = .;
.hash : { *(.hash) } /* this MUST come first! */
. = ALIGN(4096);
.eh_frame :
{
*(.eh_frame)
}
. = ALIGN(4096);
.text :
{
*(.text)
/* XXX: added for constructors */
init_start = .;
KEEP(*(.init.before.memory))
einit_before_memory = .;
KEEP(*(.init.before.fs))
einit_before_fs = .;
KEEP(*(.init.before.shell))
einit_before_shell = .;
/* XXX: added for constructors */
}
. = ALIGN(4096);
.reloc :
{
*(.reloc)
}
. = ALIGN(4096);
.data :
{
*(.rodata*)
*(.got.plt)
*(.got)
*(.data*)
*(.sdata)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
*(.rel.local)
}
. = ALIGN(4096);
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
.rela :
{
*(.rela.*) /* XXX: added to squash relocation sections */
*(.rela.data*)
*(.rela.got)
*(.rela.stab)
}
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
.ignored.reloc :
{
*(.rela.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 : { *(.comment) }
}