This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
binutils + 16-bit code issues
- From: Anatol Pomozov <anatol dot pomozov at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 22 Sep 2017 17:04:53 -0700
- Subject: binutils + 16-bit code issues
- Authentication-results: sourceware.org; auth=none
Hi
I am writing a bootloader for x86. Here is a simplified version of my
code https://gist.github.com/anatol/49ee2dfc6ad5da3acb3396e876a59669
In the most of the OsDev examples there is a recommendation to use
NASM assembler. It usually compiles asm code with "nasm -f bin .."
flag i.e. output to raw binary. I am trying to do the same with GAS:
$ as --version
GNU assembler (GNU Binutils for Debian) 2.28
$ as boot.S -o boot.o
$ ld boot.o -o boot --oformat binary
boot.o: In function `_start':
(.text+0x5): relocation truncated to fit: R_X86_64_16 against `.text'+28
boot.o: In function `_start':
(.text+0x12): relocation truncated to fit: R_X86_64_16 against `.text'+32
Unfortunately the error message does not make it easy for me to
understand what is going on here. And how to fix the error. After
googling I found a recommendation to run as/ld in 32bit mode. So I
tried it as well:
$ as boot.S -o boot.o --32
$ ld boot.o -o boot --oformat binary -melf_i386
boot.o: In function `_start':
(.text+0x5): relocation truncated to fit: R_386_16 against `.text'
boot.o: In function `_start':
(.text+0x12): relocation truncated to fit: R_386_16 against `.text'
And again the same "relocation truncated to fit". So does it really
mean? How to fix it? Are the any good examples of using 16-bit code
with GAS?