bebbo / binutils-gdb

Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
3 stars 3 forks source link

SUBALIGN does not Appear to Work #30

Closed RetroRevivalGames closed 1 year ago

RetroRevivalGames commented 1 year ago

Hi Bebbo. Since #29 I've gotten a ROM image for the SEGA Mega Drive to build and run successfully.

I've come across one more minor issue. I'm using -ffunction-sections and -fdata-sections along with --gc-sections to reduce ROM size. It works nicely but the linker seems to force a 4-byte alignment between each input section. In other words, each function/variable now has a few 0 bytes to align the next function/variable on a 4-byte boundary, which can chew up some space for larger programs. I'm trying to align on a 2-byte boundary.

Same lds. I've tried different values for the .text section's SUBALIGN command (0, 1, 2, 3, 4) and each time it aligns on a 4-byte boundary.

ENTRY(__START)

MEMORY
{
    rom (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00400000
    ram (rwx) : ORIGIN = 0x00FF0000, LENGTH = 0x00010000
}

SECTIONS
{
    .text 0x00000000 : SUBALIGN(2) {
        KEEP(*(.header))
        *(.boot)
        *(.main)
        *(.text*)
        *(.vdp)
        *(.rodata .rodata.*)
    } > rom
    __stext = SIZEOF(.text);

    .data 0x00FF0000 : AT( ADDR(.text) + SIZEOF(.text) ) {
        *(.data*)
        *(.asmdata)
        FILL(0x00)
        . = ALIGN(2);
    } > ram
    __sdata = SIZEOF(.data);

    .bss 0x00FF0000 + SIZEOF(.data) : {
        *(.bss) 
    } > ram
}

image

Not sure how much it would take to remedy this but if it's not too much of a hassle it'd be awesome if this was implemented.

I've done a little research into it. Looks like asection struct has align_power variable. Not sure if that could be used to allow users to configure the input section alignments via SUBALIGN?

bebbo commented 1 year ago

the assembler already aligns everything at 4 byte boundaries:

START:
  rts

->

00000000 00000000 START:
   0:   4e75            rts
   2:   0000    .short 0x0000
bebbo commented 1 year ago

and it's hard coded atm:

newsect->alignment_power = 2;
bebbo commented 1 year ago

And last but not least: the Amiga hunk file format supports only multiples of 4. => this won't work using Amiga hunks.

workarounds:

RetroRevivalGames commented 1 year ago

Makes sense. I figured hunk would have that alignment limitation.

As far as using a different target, this toolchain only supports hunk correct? I remember trying to compile amiga-gcc with TARGET=m68k-elf and it failed.

bebbo commented 1 year ago

Makes sense. I figured hunk would have that alignment limitation.

As far as using a different target, this toolchain only supports hunk correct? I remember trying to compile amiga-gcc with TARGET=m68k-elf and it failed.

a) why aren't you using a stock m68k-elf? b) make TARGET=m68k-elf gcc should work, but other stuff fails...

RetroRevivalGames commented 1 year ago

a) why aren't you using a stock m68k-elf?

Stack heavy / slower assembly generated

b) make TARGET=m68k-elf gcc should work, but other stuff fails...

Unfortunately this is failing at binutils gas. Looks like some functions aren't getting proper parameters.

image

image

bebbo commented 1 year ago

try again in 30 mins

bebbo commented 1 year ago

make binutils -j30 TARGET=m68k-elf make binutils bfd... make binutils bfd...done make binutils gas... make binutils gas...done make binutils binutils... make binutils binutils...done make binutils ld... make binutils ld...done install binutils... install binutils...done

RetroRevivalGames commented 1 year ago

OK. Building only binutils does work. I was building all of gcc using make gcc TARGET=m68k-elf

bebbo commented 1 year ago

gcc should compile too, but not newlib

RetroRevivalGames commented 1 year ago

Tried it again. Yes, looks like it built correctly. Tried it out and it works perfectly. Exactly what I was looking for, the high efficiency of your assembly generation with the elf binary format. I even got lto plugins to work with small modifications to the Makefile in amiga-gcc. Just remove --disable-plugins from binutils configuration.

Thank you Bebbo.

bebbo commented 1 year ago

Tried it again. Yes, looks like it built correctly. Tried it out and it works perfectly. Exactly what I was looking for, the high efficiency of your assembly generation with the elf binary format. I even got lto plugins to work with small modifications to the Makefile in amiga-gcc. Just remove --disable-plugins from binutils configuration.

Thank you Bebbo.

I will omit --disable-plugins if target is m68k-elf.