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

2022-04-19 Thread grischka

Sam Ellicott wrote:

Example code is here
```
.global _start
_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


Thanks!



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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

2022-04-18 Thread Sam Ellicott
Example code is here
```
.global _start
_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.
Thanks!

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


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

2022-04-16 Thread grischka
Example?

On April 16, 2022 5:03:59 AM UTC, Sam Ellicott  wrote:
>Hi All,
>I have been working on porting tcc to generate code for riscv32
>targets and have run into an issue when writing the assembler in the
>case of an externally defined symbol. 
...

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] TCC riscv32 port - Deferring code generation on external symbol

2022-04-15 Thread Sam Ellicott
Hi All,
I have been working on porting tcc to generate code for riscv32
targets and have run into an issue when writing the assembler in the
case of an externally defined symbol. Since the symbol will not be
defined until link time I need to defer the code generation to the
linking step. However, I haven't been able to ascertain 1) what to
check for in a symbol that lets me know that I do not have enough
information for code generation (VT_EXTERN flag?), 2) how to let the
linker know where and what code it should generate to populate the
symbol load. I've been poking through other architecture's code but
haven't had much luck.
Thanks,
-Sam Ellicott
Soli Deo Gloria

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel