hippy
Posts: 8555
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

[SOLVED] Life's a GAS, or maybe not!

Sun Sep 27, 2020 8:40 pm

This works ...

Code: Select all

pi@Pi3B:~/apps/sol $ as -o xyzzy.o xyzzy.hll.sol.pi
pi@Pi3B:~/apps/sol $ gcc -o xyzzy.exe xyzzy.o
pi@Pi3B:~/apps/sol $ ./xyzzy.exe
Yippee!
But this doesn't ...

Code: Select all

pi@Pi3B:~/apps/sol $ as -g -o xyzzy.o xyzzy.hll.sol.pi
xyzzy.hll.sol.pi: Assembler messages:
xyzzy.hll.sol.pi: Error: unaligned opcodes detected in executable segment
So how do I find what it thinks are those unaligned opcodes and where they are ?

I can't see anything in the source, nor anything obvious when I get 'as' to produce a listing file, no error message which says "this here is unaligned".
Last edited by hippy on Mon Sep 28, 2020 7:20 am, edited 1 time in total.

trejan
Posts: 2979
Joined: Tue Jul 02, 2019 2:28 pm

Re: Life's a GAS, or maybe not!

Sun Sep 27, 2020 9:00 pm

You enabled debug and as is emitting DWARF debug info like the address mapping for code to source line. Your error is because it is assuming everything will be a multiple of 2 bytes since DWARF2_LINE_MIN_INSN_LENGTH is set to 2 but somewhere you're adding a single byte to a segment.

You'll have to dig around in your code to work out what exactly is causing this. Check data as well.

hippy
Posts: 8555
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Life's a GAS, or maybe not!

Sun Sep 27, 2020 9:45 pm

trejan wrote:
Sun Sep 27, 2020 9:00 pm
You'll have to dig around in your code to work out what exactly is causing this.
That's the problem; how ?

Everything is aligned on 4-byte boundaries, lower two lsb's zero. I'm only using 32-bit data and that's aligned. Every '.asciz' has a '.align 2' so that doesn't appear to be it. And there's nothing left which I can see to explain it.

User avatar
jahboater
Posts: 6290
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Life's a GAS, or maybe not!

Sun Sep 27, 2020 10:12 pm

Could you post the code?
It must be quite small, or does it do more than print Yippee! ?
Pi4 8GB running PIOS64 Lite

hippy
Posts: 8555
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: [SOLVED] Life's a GAS, or maybe not!

Mon Sep 28, 2020 7:32 am

It's generated code with a full-blown Virtual Machine implementation included so there's a bit more to it than just a 'print', but the source size would be manageable.

Having battled through adding print commands to debug a tricky part of task scheduling I thought it was time to learn how to use 'gdb', which is where what was working fell apart.

I have however resolved the issue. Not so much "unaligned opcodes" as the image not being padded to be multiples of two/four bytes as trejan predicted. I had inserted my '.align 2' before my '.asciz' so that aligned their address and padded previous '.asciz' but could leave a trailing number of odd bytes at the end of the program. Moving the '.align' to after '.asciz', or a final '.align' at the end of the program, pads things out as required.

"Unaligned opcodes" had me focusing on what opcodes there were, not what opcodes there weren't.

Return to “Bare metal, Assembly language”