Port-amd64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Build a file with -m32



Emmanuel Dreyfus <manu%netbsd.org@localhost> wrote:

> /home2/manu/src/obj/tooldir.NetBSD-8.1-amd64/bin/x86_64--netbsd-ld: i386
> architecture of input file `multiboot2_32.o' is incompatible with
> i386:x86-64 output

I made good progress on this subject. Using objcopy, I have been able to link an
object build with -m32 into an amd64 kernel.

In src/sys/arch/amd64/conf/Makefile.amd64 I have alternate of KCOMPILE and
NORMAL_C that add -m32, turn -mcmodel=kernel into -mcmodem=32 and use
objcopy to turn the result into a 64 objects. 

KCOMPILE32.c=    ${CC} ${COPTS.${<:T}} -m32 \
                 ${CFLAGS:C/-mcmodel=[a-z]*/-mcmodel=32/} \
                 ${CPPFLAGS} -c $< -o $@32

NORMAL_C32?=    @${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}" && \
                ${_MKSHECHO} ${KCOMPILE32.c} ${PROF} && \
                ${KCOMPILE32.c} ${PROF} && \  
                ${OBJCOPY} -g -O elf64-x86-64 $@32 $@ && \
                ${COMPILE_CTFCONVERT}

In src/sys/arch/amd64/conf/files.amd64

# Multiboot support
defflag opt_multiboot.h MULTIBOOT
file    arch/amd64/amd64/multiboot_locore.S     multiboot
file    arch/x86/x86/multiboot2.c    multiboot
file    arch/x86/x86/multiboot32.c  multiboot compile-with "${NORMAL_C32}"

The resulting 32 bit object must be at the beginning of the kernel to avoid
relocation truncation errors at link time. I do this in
src/sys/arch/amd64/conf/kern.ldscript:
        .text : AT (ADDR(.text) & 0x0fffffff)
        { 
                . = ALIGN(__PAGE_SIZE);
                *(multiboot)
                . = ALIGN(__PAGE_SIZE);
                __text_user_start = . ;
                *(.text.user)
                . = ALIGN(__PAGE_SIZE);
                __text_user_end = . ;

                multiboot32.o(.text)
                *(.text)
                *(.text.*)
                *(.stub)
                . = ALIGN(__LARGE_PAGE_SIZE);
        } =0xCC

Any comment on the approach?

There is another minor problem: the code built with -m32 wants some i386
includes. I needed in the build directory a link i386 ->
src/sys/arch/i386/include and an empty  opt_kernbase.h file. How should this be
added by the build system?

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index