title: RISC V assembly alignment errors
body: <p>I am trying to build a Forth-like threaded interpretive language (TIL) using the Spike RISC-V emulator and the pk kernel. I am using riscv64-unknown-elf-gcc to build the ELFs.</p>
  <p>I am having a lot of issues with alignment - I believe the code should be eight-byte aligned and for a while I got that by sticking a nop in the header generating macro (for those that don't know TILs, the commands are generally built out of blocks of assembly which have a standard structure - I am using a macro to generate the structure.</p>
  <p>I have just extended the code alot - adding more keywords etc - and the alignment issue is back again. Eg:</p>
  <pre><code>riscv64-unknown-elf-gcc -o riscyforth riscyforth.S
  ...... /../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccpobhjr.o(.text+0x679): 7 bytes required for alignment to 8-byte boundary, but only 6 present
  ..... /../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: can't relax section: bad value
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p>This is the macro generating the function headers:</p>
  <pre><code>.macro CODEHEADER Name, PrevName, flags
  .balign 8
  TIL_\Name:
          .4byte  \flags
          .4byte  \Name
  ptr_\PrevName:
          .4byte TIL_\PrevName
  length_ASCII_\Name:
          .4byte end_\Name - beg_\Name
  beg_\Name:
          .ascii &quot;\Name&quot; 
  end_\Name:
          .balign 8
  \Name:
  .endm
  </code></pre>
  <p>The executable code begins at \Name and this is where I am trying to guarantee 8 byte alignment - eg a typical function might look like (this one puts a 1 on the stack):</p>
  <pre><code>           CODEHEADER 1, DOT
              li t0, 1
              PUSH t0
              tail NEXT
  </code></pre>
  <p>and the <code>li t0, 1</code> would be the found at <code>\Name</code> where Name was <code>1</code>.</p>
  <p>Is there a way to guarantee this alignment? I cannot find anything in online documentation but wondered if any users had heuristics here?</p>