[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] TCC riscv32 port - Deferring code generation on exter

From: grischka
Subject: Re: [Tinycc-devel] TCC riscv32 port - Deferring code generation on external symbol
Date: Tue, 19 Apr 2022 16:53:29 +0200
User-agent: Thunderbird (Windows/20090812)

Sam Ellicott wrote:
Example code is here
.global _start
la gp, _global_pointer
la a0, _bss_start
la a1, _bss_end
bgeu a0, a1, 2f
1: sw zero, (a0)
addi a0, a0, 4
bltu a0, a1, 1b
2: # setup the stack
la sp, _stack_end
call main
For example when the `_global_pointer` symbol is encountered what is
the correct behavior? Since the symbol is defined in a separate
compilation unit, I'm assuming some sort of marker needs to be placed
in the .o file to indicate what immediate value goes there at link
time. However, I don't know what that is, or how it is generated.
Similarly for `_bss_start`, `_bss_end`, etc.

That 'sort of marker' thing is called 'relocation' entry.

You would emit code as if it were  'la a0, 0' but put a relocation on
it that refers to the symbol.  (In tcc, using 'greloc[a]' for example).

Whether or not the symbol is defined in the current unit doesn't really
make a difference in that regard.

With riscv it's maybe two relocations as I've seen that 'la' really is
two instructions to first load the 20 HI-bits and then the 12 LO-bits.

-- gr


reply via email to

[Prev in Thread] Current Thread [Next in Thread]