Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #380609

Re: Call to a function

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Call to a function
Date 2024-01-21 20:14 -0800
Organization None to speak of
Message-ID <877ck2atsn.fsf@nosuchdomain.example.com> (permalink)
References (8 earlier) <87leblhzud.fsf@nosuchdomain.example.com> <865y1yxiyw.fsf@linuxsc.com> <87fs11e8yz.fsf@nosuchdomain.example.com> <86bk9hjbey.fsf@linuxsc.com> <uoknaf$j1rr$2@dont-email.me>

Show all headers | View raw


Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Fri, 19 Jan 2024 12:49:57 -0800, Tim Rentsch wrote:
>> An exception to that rule is elaborate
>> function pointers, which can use very large structured values to
>> represent a pointer to function.
>
> Real-world example: PowerPC/POWER, where a function reference is two 
> addresses, one for the code and the other for, I think it’s called the GOT 
> (“Global Object Table”). Every piece of code assumes its GOT register has 
> been set up with the right value.

According to <https://devblogs.microsoft.com/oldnewthing/20180816-00/?p=99505>:

    Since each function requires its table of contents to be set
    properly, a function pointer on PowerPC is not a pointer to the
    first instruction. Instead, it’s a pointer to a structure
    consisting of two pointers: The first pointer points to the
    first instruction of the function, and the second pointer is
    the table of contents for the function.

A quick experiment with a gcc powerpc cross-compiler
(powerpc-linux-gnu-gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0) indicates that
void* and function pointers are the same size, 4 bytes.

I suppose compilers *could* have used that two-pointer structure as the
representation of a function pointer.  Possibly that would have broken
code that makes invalid assumptions about function pointer sizes.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Call to a function Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-19 12:49 -0800
  Re: Call to a function Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-22 03:27 +0000
    Re: Call to a function Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-21 20:14 -0800
    Re: Call to a function scott@slp53.sl.home (Scott Lurndal) - 2024-01-22 16:36 +0000
      Re: Call to a function Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-22 22:05 +0000

csiph-web