OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:03 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Empty ctor section with 32bit bootstrap code
PostPosted: Wed May 17, 2017 3:54 am 
Offline

Joined: Sun Nov 08, 2015 1:20 pm
Posts: 6
Hey guys,

I'm building a long mode kernel with an embedded 32 bit bootstrap code. I have one global constructor in the bootstrap code. I compile the bootstrap code with -m elf_i386 and objcopy it into and x86_64 elf for the linking step. The output object of the objcopy still consists of the ctor section:

Quote:
>build$ objdump -h boot.cpp.32.o

boot.cpp.32.o: Dateiformat elf64-x86-64

Sektionen:
Idx Name Größe VMA LMA Datei-Off Ausr.
0 .text 0000011d 0000000000000000 0000000000000000 00000040 2**0
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 0000015d 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000040 0000000000000000 0000000000000000 00000160 2**5
ALLOC
3 .rodata 0000000c 0000000000000000 0000000000000000 00000160 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .ctors 00000004 0000000000000000 0000000000000000 0000016c 2**2
CONTENTS, ALLOC, LOAD, RELOC, DATA
5 .comment 00000012 0000000000000000 0000000000000000 00000170 2**0
CONTENTS, READONLY
6 .eh_frame 000000bc 0000000000000000 0000000000000000 00000184 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA


My linking script looks like that:

Code:
ENTRY(_start)

SECTIONS {
        . = 1M;
   
        .multiboot BLOCK(4K) : ALIGN(4K) {
                *(.multiboot)
                <<ALL_BOOTSTRAP_FILES>>  (.text)
        }

        .rodata BLOCK(4K) : ALIGN(4K) {
                start_ctors = .;
                KEEP (*(SORT(.ctors*)))
                end_ctors = .;

                start_dtors = .;
                *(SORT(.dtors*))
                end_dtors = .;
   
                *(.rodata)
        }
         .text BLOCK(4K) : ALIGN(4K) {
                _code64 = .;
                *(EXCLUDE_FILE(<<ALL_BOOTSTRAP_FILES>>) .text)
                *(.rodata*)
                . = ALIGN(4096);
        }

        .data BLOCK(4K) : ALIGN(4K) {
                *(.data)
        }

        .bss BLOCK(4K) : ALIGN(4K) {
                *(COMMON)
                *(.bss)
        }
}


In the resulting binary the linker discards the ctor section:

Quote:
>build$ readelf -s src/kernel/x86_64_pc.bin | grep ctor
60: 0000000000106000 0 NOTYPE GLOBAL DEFAULT 2 start_ctors
107: 0000000000106000 0 NOTYPE GLOBAL DEFAULT 2 end_


I tried like 100 different things: Instead of the "KEEP (*(SORT(.ctors*)))" use "KEEP (boot32.cpp.32.o (SORT(.ctors*)))", disabling optimization, ...

Has anyone any idea why this is happening?

Thanks
Nils


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 65 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group