âld: Unsupported PEI architecture: pei-i386â error when using LD
I'm trying to assemble a C file and a ASM file together and somehow I get this "ld: Unsupported PEI architecture: pei-i386"
error when using LD. I used this tutorial with some modified code from an answer to this question
Following the entire set of the files of interest
1) The main Assembly file
;;kernel.asm
bits 32 ;nasm directive - 32 bit
global entry
extern _kmain ;kmain is defined in the c file
section .text
entry: jmp start
;multiboot spec
align 4
dd 0x1BADB002 ;magic
dd 0x00 ;flags
dd -(0x1BADB002 + 0x00) ;checksum. m+f+c should be zero
start:
cli ;block interrupts
mov esp, stack_space ;set stack pointer
call _kmain
hlt ;halt the CPU
section .bss
resb 8192 ;8KB for stack
stack_space:
2) The C file
/*
* kernel.c
*/
void kmain(void)
const char *str = "kernel 1.0";
char *vidptr = (char*)0xb8000; // video mem begins here
unsigned int j = 0;
unsigned int i = 0;
while(j < 80 * 25 * 2)
/* blank char */
vidptr[j] = ' ';
/* attr. byte - light gray on black screen */
vidptr[j+1] = 0x07;
j = j + 2;
j = 0;
/* this loop writes the string into vram */
while(str[j] != '')
/* the characters ASCII */
vidptr[i] = str[j];
/* atr. byte - give character black bg and light gray fg */
vidptr[i + 1] = 0x07;
++j;
i = i + 2;
3) The Linker file
/*
* link.ld
*/
OUTPUT_FORMAT(pei-i386)
ENTRY(entry)
SECTIONS
. = 0x100000;
.text : *(.text)
.data : *(.data)
.bss : *(.bss)
4) a Batch file I made for simplifying the process to build it all. I'm using cygwin
@echo off
echo Building...
nasm -f elf32 kernel.asm -o kasm.o
echo ok
gcc -m32 -c kernel.c -o kc.o -ffreestanding -nostdlib -nostdinc
echo ok
ld -T link.ld -o kernel kasm.o kc.o -build-id=none
echo ok
objcopy -O elf32-i386 kernel kernel.elf
echo ok
echo Done.
How to fix this error?
c assembly linker
 |Â
show 5 more comments
I'm trying to assemble a C file and a ASM file together and somehow I get this "ld: Unsupported PEI architecture: pei-i386"
error when using LD. I used this tutorial with some modified code from an answer to this question
Following the entire set of the files of interest
1) The main Assembly file
;;kernel.asm
bits 32 ;nasm directive - 32 bit
global entry
extern _kmain ;kmain is defined in the c file
section .text
entry: jmp start
;multiboot spec
align 4
dd 0x1BADB002 ;magic
dd 0x00 ;flags
dd -(0x1BADB002 + 0x00) ;checksum. m+f+c should be zero
start:
cli ;block interrupts
mov esp, stack_space ;set stack pointer
call _kmain
hlt ;halt the CPU
section .bss
resb 8192 ;8KB for stack
stack_space:
2) The C file
/*
* kernel.c
*/
void kmain(void)
const char *str = "kernel 1.0";
char *vidptr = (char*)0xb8000; // video mem begins here
unsigned int j = 0;
unsigned int i = 0;
while(j < 80 * 25 * 2)
/* blank char */
vidptr[j] = ' ';
/* attr. byte - light gray on black screen */
vidptr[j+1] = 0x07;
j = j + 2;
j = 0;
/* this loop writes the string into vram */
while(str[j] != '')
/* the characters ASCII */
vidptr[i] = str[j];
/* atr. byte - give character black bg and light gray fg */
vidptr[i + 1] = 0x07;
++j;
i = i + 2;
3) The Linker file
/*
* link.ld
*/
OUTPUT_FORMAT(pei-i386)
ENTRY(entry)
SECTIONS
. = 0x100000;
.text : *(.text)
.data : *(.data)
.bss : *(.bss)
4) a Batch file I made for simplifying the process to build it all. I'm using cygwin
@echo off
echo Building...
nasm -f elf32 kernel.asm -o kasm.o
echo ok
gcc -m32 -c kernel.c -o kc.o -ffreestanding -nostdlib -nostdinc
echo ok
ld -T link.ld -o kernel kasm.o kc.o -build-id=none
echo ok
objcopy -O elf32-i386 kernel kernel.elf
echo ok
echo Done.
How to fix this error?
c assembly linker
1
I am confused, if everthing is elf, why do you usepei-i386
?
â Jester
Nov 10 at 22:49
In the original tutorial, it said in the link file at the place of pei-i386 that you had to use elf32-i386, and that did not work for me at all. When the batch file gets ran it outputs:Building... ok ok ld: Unsupported PEI architecture: pei-i386 ok objcopy: error: the input file 'kernel' is empty ok Done.
â Ryelow
Nov 10 at 22:53
@Jester : because his linker apparently only generates WinPE executables (although it is able to read elf objects). Objcopy though is more universal and can convert to ELF. If an elf cross compiler/toolchain were being used this wouldn't be an issue of course. Using a native tool chain can lead to this kind of stuff.
â Michael Petch
Nov 11 at 0:04
What happens if you removeOUTPUT_FORMAT(pei-i386)
from your linker script?
â Michael Petch
Nov 11 at 0:13
Sorry I could not respond. When I remove Output_Format from my linker script it returns:ld: i386 architecture of input file
kasm.o' is incompatible with i386:x86-64 output ld: i386 architecture of input filekc.o' is incompatible with i386:x86-64 output
@MichaelPetch
â Ryelow
Nov 11 at 2:48
 |Â
show 5 more comments
I'm trying to assemble a C file and a ASM file together and somehow I get this "ld: Unsupported PEI architecture: pei-i386"
error when using LD. I used this tutorial with some modified code from an answer to this question
Following the entire set of the files of interest
1) The main Assembly file
;;kernel.asm
bits 32 ;nasm directive - 32 bit
global entry
extern _kmain ;kmain is defined in the c file
section .text
entry: jmp start
;multiboot spec
align 4
dd 0x1BADB002 ;magic
dd 0x00 ;flags
dd -(0x1BADB002 + 0x00) ;checksum. m+f+c should be zero
start:
cli ;block interrupts
mov esp, stack_space ;set stack pointer
call _kmain
hlt ;halt the CPU
section .bss
resb 8192 ;8KB for stack
stack_space:
2) The C file
/*
* kernel.c
*/
void kmain(void)
const char *str = "kernel 1.0";
char *vidptr = (char*)0xb8000; // video mem begins here
unsigned int j = 0;
unsigned int i = 0;
while(j < 80 * 25 * 2)
/* blank char */
vidptr[j] = ' ';
/* attr. byte - light gray on black screen */
vidptr[j+1] = 0x07;
j = j + 2;
j = 0;
/* this loop writes the string into vram */
while(str[j] != '')
/* the characters ASCII */
vidptr[i] = str[j];
/* atr. byte - give character black bg and light gray fg */
vidptr[i + 1] = 0x07;
++j;
i = i + 2;
3) The Linker file
/*
* link.ld
*/
OUTPUT_FORMAT(pei-i386)
ENTRY(entry)
SECTIONS
. = 0x100000;
.text : *(.text)
.data : *(.data)
.bss : *(.bss)
4) a Batch file I made for simplifying the process to build it all. I'm using cygwin
@echo off
echo Building...
nasm -f elf32 kernel.asm -o kasm.o
echo ok
gcc -m32 -c kernel.c -o kc.o -ffreestanding -nostdlib -nostdinc
echo ok
ld -T link.ld -o kernel kasm.o kc.o -build-id=none
echo ok
objcopy -O elf32-i386 kernel kernel.elf
echo ok
echo Done.
How to fix this error?
c assembly linker
I'm trying to assemble a C file and a ASM file together and somehow I get this "ld: Unsupported PEI architecture: pei-i386"
error when using LD. I used this tutorial with some modified code from an answer to this question
Following the entire set of the files of interest
1) The main Assembly file
;;kernel.asm
bits 32 ;nasm directive - 32 bit
global entry
extern _kmain ;kmain is defined in the c file
section .text
entry: jmp start
;multiboot spec
align 4
dd 0x1BADB002 ;magic
dd 0x00 ;flags
dd -(0x1BADB002 + 0x00) ;checksum. m+f+c should be zero
start:
cli ;block interrupts
mov esp, stack_space ;set stack pointer
call _kmain
hlt ;halt the CPU
section .bss
resb 8192 ;8KB for stack
stack_space:
2) The C file
/*
* kernel.c
*/
void kmain(void)
const char *str = "kernel 1.0";
char *vidptr = (char*)0xb8000; // video mem begins here
unsigned int j = 0;
unsigned int i = 0;
while(j < 80 * 25 * 2)
/* blank char */
vidptr[j] = ' ';
/* attr. byte - light gray on black screen */
vidptr[j+1] = 0x07;
j = j + 2;
j = 0;
/* this loop writes the string into vram */
while(str[j] != '')
/* the characters ASCII */
vidptr[i] = str[j];
/* atr. byte - give character black bg and light gray fg */
vidptr[i + 1] = 0x07;
++j;
i = i + 2;
3) The Linker file
/*
* link.ld
*/
OUTPUT_FORMAT(pei-i386)
ENTRY(entry)
SECTIONS
. = 0x100000;
.text : *(.text)
.data : *(.data)
.bss : *(.bss)
4) a Batch file I made for simplifying the process to build it all. I'm using cygwin
@echo off
echo Building...
nasm -f elf32 kernel.asm -o kasm.o
echo ok
gcc -m32 -c kernel.c -o kc.o -ffreestanding -nostdlib -nostdinc
echo ok
ld -T link.ld -o kernel kasm.o kc.o -build-id=none
echo ok
objcopy -O elf32-i386 kernel kernel.elf
echo ok
echo Done.
How to fix this error?
c assembly linker
c assembly linker
edited Nov 11 at 3:09
Antonino
1,45911227
1,45911227
asked Nov 10 at 22:48
Ryelow
12
12
1
I am confused, if everthing is elf, why do you usepei-i386
?
â Jester
Nov 10 at 22:49
In the original tutorial, it said in the link file at the place of pei-i386 that you had to use elf32-i386, and that did not work for me at all. When the batch file gets ran it outputs:Building... ok ok ld: Unsupported PEI architecture: pei-i386 ok objcopy: error: the input file 'kernel' is empty ok Done.
â Ryelow
Nov 10 at 22:53
@Jester : because his linker apparently only generates WinPE executables (although it is able to read elf objects). Objcopy though is more universal and can convert to ELF. If an elf cross compiler/toolchain were being used this wouldn't be an issue of course. Using a native tool chain can lead to this kind of stuff.
â Michael Petch
Nov 11 at 0:04
What happens if you removeOUTPUT_FORMAT(pei-i386)
from your linker script?
â Michael Petch
Nov 11 at 0:13
Sorry I could not respond. When I remove Output_Format from my linker script it returns:ld: i386 architecture of input file
kasm.o' is incompatible with i386:x86-64 output ld: i386 architecture of input filekc.o' is incompatible with i386:x86-64 output
@MichaelPetch
â Ryelow
Nov 11 at 2:48
 |Â
show 5 more comments
1
I am confused, if everthing is elf, why do you usepei-i386
?
â Jester
Nov 10 at 22:49
In the original tutorial, it said in the link file at the place of pei-i386 that you had to use elf32-i386, and that did not work for me at all. When the batch file gets ran it outputs:Building... ok ok ld: Unsupported PEI architecture: pei-i386 ok objcopy: error: the input file 'kernel' is empty ok Done.
â Ryelow
Nov 10 at 22:53
@Jester : because his linker apparently only generates WinPE executables (although it is able to read elf objects). Objcopy though is more universal and can convert to ELF. If an elf cross compiler/toolchain were being used this wouldn't be an issue of course. Using a native tool chain can lead to this kind of stuff.
â Michael Petch
Nov 11 at 0:04
What happens if you removeOUTPUT_FORMAT(pei-i386)
from your linker script?
â Michael Petch
Nov 11 at 0:13
Sorry I could not respond. When I remove Output_Format from my linker script it returns:ld: i386 architecture of input file
kasm.o' is incompatible with i386:x86-64 output ld: i386 architecture of input filekc.o' is incompatible with i386:x86-64 output
@MichaelPetch
â Ryelow
Nov 11 at 2:48
1
1
I am confused, if everthing is elf, why do you use
pei-i386
?â Jester
Nov 10 at 22:49
I am confused, if everthing is elf, why do you use
pei-i386
?â Jester
Nov 10 at 22:49
In the original tutorial, it said in the link file at the place of pei-i386 that you had to use elf32-i386, and that did not work for me at all. When the batch file gets ran it outputs:
Building... ok ok ld: Unsupported PEI architecture: pei-i386 ok objcopy: error: the input file 'kernel' is empty ok Done.
â Ryelow
Nov 10 at 22:53
In the original tutorial, it said in the link file at the place of pei-i386 that you had to use elf32-i386, and that did not work for me at all. When the batch file gets ran it outputs:
Building... ok ok ld: Unsupported PEI architecture: pei-i386 ok objcopy: error: the input file 'kernel' is empty ok Done.
â Ryelow
Nov 10 at 22:53
@Jester : because his linker apparently only generates WinPE executables (although it is able to read elf objects). Objcopy though is more universal and can convert to ELF. If an elf cross compiler/toolchain were being used this wouldn't be an issue of course. Using a native tool chain can lead to this kind of stuff.
â Michael Petch
Nov 11 at 0:04
@Jester : because his linker apparently only generates WinPE executables (although it is able to read elf objects). Objcopy though is more universal and can convert to ELF. If an elf cross compiler/toolchain were being used this wouldn't be an issue of course. Using a native tool chain can lead to this kind of stuff.
â Michael Petch
Nov 11 at 0:04
What happens if you remove
OUTPUT_FORMAT(pei-i386)
from your linker script?â Michael Petch
Nov 11 at 0:13
What happens if you remove
OUTPUT_FORMAT(pei-i386)
from your linker script?â Michael Petch
Nov 11 at 0:13
Sorry I could not respond. When I remove Output_Format from my linker script it returns:
ld: i386 architecture of input file
kasm.o' is incompatible with i386:x86-64 output ld: i386 architecture of input file kc.o' is incompatible with i386:x86-64 output
@MichaelPetchâ Ryelow
Nov 11 at 2:48
Sorry I could not respond. When I remove Output_Format from my linker script it returns:
ld: i386 architecture of input file
kasm.o' is incompatible with i386:x86-64 output ld: i386 architecture of input file kc.o' is incompatible with i386:x86-64 output
@MichaelPetchâ Ryelow
Nov 11 at 2:48
 |Â
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid â¦
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244181%2fld-unsupported-pei-architecture-pei-i386-error-when-using-ld%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I am confused, if everthing is elf, why do you use
pei-i386
?â Jester
Nov 10 at 22:49
In the original tutorial, it said in the link file at the place of pei-i386 that you had to use elf32-i386, and that did not work for me at all. When the batch file gets ran it outputs:
Building... ok ok ld: Unsupported PEI architecture: pei-i386 ok objcopy: error: the input file 'kernel' is empty ok Done.
â Ryelow
Nov 10 at 22:53
@Jester : because his linker apparently only generates WinPE executables (although it is able to read elf objects). Objcopy though is more universal and can convert to ELF. If an elf cross compiler/toolchain were being used this wouldn't be an issue of course. Using a native tool chain can lead to this kind of stuff.
â Michael Petch
Nov 11 at 0:04
What happens if you remove
OUTPUT_FORMAT(pei-i386)
from your linker script?â Michael Petch
Nov 11 at 0:13
Sorry I could not respond. When I remove Output_Format from my linker script it returns:
ld: i386 architecture of input file
kasm.o' is incompatible with i386:x86-64 output ld: i386 architecture of input filekc.o' is incompatible with i386:x86-64 output
@MichaelPetchâ Ryelow
Nov 11 at 2:48