Skip to content

Linker misaligns section in 16-bit RAW #523

@chibicitiberiu

Description

@chibicitiberiu

Hello,
I am trying to create a raw binary which is basically the 2nd stage of a bootloader. I am using the following linker script:

FORMAT RAW BIN 
OPTION QUIET,
       NODEFAULTLIBS,
       START=entry, 
       VERBOSE,
       OFFSET=0,
       STACK=0x200
ORDER
    CLNAME CODE
        SEGMENT _ENTRY
        SEGMENT _TEXT
    CLNAME DATA

The C files are compiled with wcc -3 -d3 -s -wx -ms -zl -zq, and the assembly code with NASM. I am using the 2.0 release from the sourceforge page, and compiling from latest 64-bit Ubuntu.

The problem I'm having is this:

Segment                Class          Group          Address         Size
=======                =====          =====          =======         ====

_ENTRY                 CODE           AUTO           00000000        00000013
_TEXT                  CODE           AUTO           00000013        00000b8c
CONST                  DATA           DGROUP         00000ba0        00000134
CONST2                 DATA           DGROUP         00000cd4        00000004
_DATA                  DATA           DGROUP         00000cd8        00000000
_BSS                   BSS            DGROUP         00000cd8        00000005

The address where the CONST section begins is wrong, 0x13 + 0xb8c = 0xb9f, not 0xba0. In the emitted binary, the beginning address of the CONST section is indeed 0xb9f, but all the references to the constants are shifted by 1 byte.

For example, when calling puts("Hello world"), I get the output ello world. Adding 1 byte to the '_ENTRY' section (which is coded in assembly), seems to temporarily 'fix' the problem. Also, making small changes in code does that, such as adding a variable, or making a variable from int8 to int16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions