tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] trying to make absolute jump


From: grischka
Subject: Re: [Tinycc-devel] trying to make absolute jump
Date: Mon, 22 Apr 2024 20:38:41 +0200
User-agent: Mozilla/5.0 (Windows NT 6.0; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

On 22.04.2024 06:16, Paul Moore wrote:
Weird processor. It only supports absolute jumps. So this is something that 
needs to be fixed up during link time. I do not know the elf details well 
enough to be able to work out how to do it

Seems like I need the jmp instruction to be a have reloc that refers to a 
symbol that matches the jump destination, say “dest1”. So I need a reference to 
Symbol “dest1” at the jump site and a definition generated later (by 
gsym_addr). Can I even do that , have a reference to a symbol that I export but 
want resolved at link time and not have ELF go “well I know that symbol, its 
right here”

Hi,

certainly it's easily possible, however assuming this 16-bit 'hack'
computer/processor doesn't really have an operating system capable
to load ELF files and hence assuming that you probably want to go
with the -Wl,-oformat=binary option, you can get away without relocation
at all.

You'd simply replace the relative patch in gsym_addr()
    write32le(ptr, a - t - 4);
by an absolute one, for example
    write16le(ptr, a + LOAD_ADDRESS);

where LOAD_ADDRESS obviously is where the program is supposed to be
loaded.

By the way, if you prefer to start hacking with something more
simple, maybe you want to have a look at tinycc's initial revision

    https://repo.or.cz/tinycc.git/commitdiff/initial

which already can compile itself, almost at least. (IIRC parsing
for 0x... hex numbers needs to be added and the #ifdefs need to
be removed.  It can handle "#define SYM VAL" though.  Also the
vac and/or vat table should be initialized with '0', IIRC)

-- gr


I thought that maybe computed goto offered a way to prise the lid off this, but 
no , that doesn’t not work the same way.





reply via email to

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