Author Topic: GCC-TDM problem when calling ld  (Read 8120 times)

Offline gomi

  • Jr. Member
  • *
  • Posts: 9
GCC-TDM problem when calling ld
« on: November 21, 2020, 07:13:34 PM »
Hello, I am trying to use ld on windows with gcc-tdm.

My steps to link:
nasm loader.asm -f elf64 -o loader_entry.o
works.

gcc -O0 -g -ffreestanding -m64 -c loader.c -o loader.o
works.

ld -o loader.bin -m i386pe -Ttext 0x1000 loader_entry.o loader.o --oformat binary
error: ld: cannot perform PE operations on non PE output file 'loader.bin'

What is the reason of that ?


Offline Wilford81J

  • Jr. Member
  • *
  • Posts: 10
Re: GCC-TDM problem when calling ld
« Reply #1 on: February 20, 2023, 07:58:18 AM »
The GCC-TDM problem when calling ld may refer to an issue with the linker in the TDM-GCC compiler suite. This can be caused by a number of factors, such as incorrect linker options, incompatible libraries, or missing dependencies. To troubleshoot this issue, you may need to review the linker command line, check for missing or incompatible libraries, and ensure that all required dependencies are installed. It may also be helpful to consult the documentation or seek assistance from the TDM-GCC community.

Thanks,
Fly AlaskasWorld
« Last Edit: February 21, 2023, 03:54:33 AM by Wilford81J »

Offline Maya69

  • Jr. Member
  • *
  • Posts: 6
Re: GCC-TDM problem when calling ld
« Reply #2 on: March 23, 2023, 08:50:51 AM »
The reason why you are getting the error "ld: cannot perform PE operations on non PE output file 'loader.bin'" is because the output format that you are using for your linker (ld) is not compatible with the output file type that you are trying to generate (binary).
In your command, you are using the option "--oformat binary" which instructs the linker to generate a binary output file format, but you are also specifying the option "-m i386pe" which instructs the linker to generate a PE (Portable Executable) output file format. These two options are incompatible and cannot be used together.
To fix the issue, you need to use an output file format that is compatible with the output file type that you want to generate. For example, if you want to generate a binary output file format, you can use the option "--oformat elf64-x86-64" instead of "--oformat binary" which will generate an ELF (Executable and Linkable Format) output file format that is compatible with the binary output file type.
Here's the modified command that you can use:
ld -o loader.bin -m elf_x86_64 -Ttext 0x1000 loader_entry.o loader.o --oformat elf64-x86-64
This should generate a binary output file format that you can use for your project. AvalonAccess Login
« Last Edit: March 24, 2023, 04:17:40 AM by Maya69 »