This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add __builtin_stack_top
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: Mike Stump <mikestump at comcast dot net>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Uros Bizjak <ubizjak at gmail dot com>
- Date: Wed, 19 Aug 2015 10:08:01 -0700
- Subject: Re: [PATCH] Add __builtin_stack_top
- Authentication-results: sourceware.org; auth=none
- References: <20150804174332 dot GN11083 at gate dot crashing dot org> <CAMe9rOq1axEMb34Zw2uudG6+5vjkiXKg7-i_8FRqMHL8DizqEw at mail dot gmail dot com> <20150804192913 dot GO11083 at gate dot crashing dot org> <CAMe9rOrrtDZxS2E3pD5DsUYox7ze1un0m8+LJ0Eo79BBLOsZgQ at mail dot gmail dot com> <20150804204506 dot GP11083 at gate dot crashing dot org> <CAMe9rOoMzgkguZ+zY24Jytpr9HnoXvu5BUP3c7K-34Gmm2SDLg at mail dot gmail dot com> <CAMe9rOrHUnJJx68qKUe0gsVVwYXNALmCR6-4UVV_V3df4KO3_A at mail dot gmail dot com> <20150819125145 dot GC8652 at gate dot crashing dot org> <CAMe9rOrymZ3N_2HTd87C-LfoHYeZ_P7myMCL9ZvikE+uU19eRg at mail dot gmail dot com> <CAMe9rOqLxX3h_Pn2Rn1Ph-FH41e1DfEG1qPheDLBNdycPa=sNw at mail dot gmail dot com> <20150819165854 dot GB32473 at gate dot crashing dot org>
On Wed, Aug 19, 2015 at 9:58 AM, Segher Boessenkool
<segher@kernel.crashing.org> wrote:
> On Wed, Aug 19, 2015 at 08:25:49AM -0700, H.J. Lu wrote:
>> Here is a patch to add __builtin_argument_pointer. I only have
>
> Sorry to be a pain but... all the other builtins use _address
> instead of _pointer, it's probably best to follow that.
>
>> -- Built-in Function: void * __builtin_argument_pointer (void)
>> This function returns the argument pointer.
>>
>> as documentation. Can you suggest a better description so that it can
>> be implemented also by other compilers?
>
> Maybe something like (heavily cut'n'pasted):
>
>
> @deftypefn {Built-in Function} {void *} __builtin_argument_address (void)
> This function is similar to @code{__builtin_frame_address} with an
> argument of 0, but it returns the address of the incoming arguments to
> the current function rather than the address of its frame.
This doesn't make senses when there is no argument or arguments
are passed in registers. To me, argument pointer is a virtual concept
and an implementation detail internal to GCC. I am not sure if another
compiler can implement it based on this description.
> The exact definition of this address depends upon the processor and the
> calling convention. Usually some arguments are passed in registers and
> the rest on the stack, and this builtin returns the address of the first
> argument that is on the stack.
>
>
>> + /* Can't use DRAP if the stack address has been taken. */
>> + if (cfun->argument_pointer_taken)
>> + sorry ("%<__builtin_argument_pointer%> not supported with stack"
>> + " realignment. This may be worked around by adding"
>> + " -maccumulate-outgoing-args.");
>
> This doesn't work with DRAP? Pity :-(
With DRAP, we do
/* Replicate the return address on the stack so that return
address can be reached via (argp - 1) slot. This is needed
to implement macro RETURN_ADDR_RTX and intrinsic function
expand_builtin_return_addr etc. */
t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
t = gen_frame_mem (word_mode, t);
insn = emit_insn (gen_push (t));
RTX_FRAME_RELATED_P (insn) = 1;
/* For the purposes of frame and register save area addressing,
we've started over with a new frame. */
m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
m->fs.realigned = true;
which doesn't work for __builtin_argument_pointer.
> The patch looks plausible, but I of course can not approve it.
>
Thanks.
--
H.J.