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

Re: Help needed for small assembler script for the iraf package



On 20 Oct 2018, at 20:05, Ole Streicher <olebole@debian.org> wrote:
> Hi Manuel (and Stefan),
> 
> first Thank you very much for digging into this!
> 
> On 20.10.2018 20:36, Manuel A. Fernandez Montecelo wrote:
>> [...]
>> and with this command: gcc -c -O2 -ffreestanding -S test.c
>> 
>> We get to this:
>> ===========================================
>> ==> test.s <==
>> [...]>         tail    sigsetjmp_placeholder@plt
>> ===========================================
>> 
>> ...and changing the name of the funtion in the assembly to
>> __sigsetjmp@plt and the name of the file to zsvjmp-riscv64.s (*):
>> 
>> ===========================================
>> .../zsvjmp $ make test
>> as   -o zsvjmp-riscv64.o zsvjmp-riscv64.s
>> ar cr libzsvjmp.a zdojmp.o zsvjmp-riscv64.o
>> gfortran -o jmptest jmptest.o -L. -lzsvjmp
>> gcc -g -g -o zzdebug zzdebug.o -L. -lzsvjmp
>> ./zzdebug
>> Status = 0, step = 0
>> Calling zdojmp
>> Status = 1, step = 1
>> All OK
>> ./jmptest
>> Status =                     0 step =                     0
>> Calling zdojmp
>> Status =                     1 step =                     1
>> All OK
>> STOP 0
>> ===========================================
>> 
>> (*) Literally:
>>  $ sed 's/sigsetjmp_placeholder@plt/__sigsetjmp@plt/g' test.s >
>> zsvjmp-riscv64.s
> 
> I am a bit surprised, since for the correct function, one must replace
> the "call subroutine" (or whatever it is called on risc64) instruction
> by a "jump to address" instruction, otherwise it won't work. That change
> is the main reason why assembler is needed (otherwise, one could just
> use the C function).
> 
> Did you change this, or is there some hidden magic?

With a sufficient optimisation level, any decent compiler will be able to
optimise this to a tail call, as was done here (the "tail" pseudo-instruction;
a normal call would use "call" followed by a return instruction), but it's not
something that can be relied upon, hence the need for assembly.

James


Reply to: