“ld: Unsupported PEI architecture: pei-i386” error when using LD










0














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?










share|improve this question



















  • 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 file kc.o' is incompatible with i386:x86-64 output @MichaelPetch
    – Ryelow
    Nov 11 at 2:48
















0














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?










share|improve this question



















  • 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 file kc.o' is incompatible with i386:x86-64 output @MichaelPetch
    – Ryelow
    Nov 11 at 2:48














0












0








0







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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 file kc.o' is incompatible with i386:x86-64 output @MichaelPetch
    – Ryelow
    Nov 11 at 2:48













  • 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 file kc.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


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線