Bug 31130 - Return of Stack Address in C_alloca
Summary: Return of Stack Address in C_alloca
Status: RESOLVED NOTABUG
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-10 06:38 UTC by yuxuan He
Modified: 2023-12-11 03:04 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yuxuan He 2023-12-10 06:38:09 UTC
hello, i found there is a return of stack address in function C_alloca located in libiberty/alloca.c
step1: initialize "depth" with address of "probe", which is a local variable.

step2: store "depth" into "new_storeage" at statement:
       ((header *) new_storage)->h.deep = depth;

step3: return "new_storage" with a offset.

can you help me to confirm:
1. is this a return of stack address(or stack address can be manipulated out of the function by subtracting the offset).
2. is the implementation of this function is on purpose?
Comment 1 Alan Modra 2023-12-10 20:54:56 UTC
(In reply to yuxuan He from comment #0)
> hello, i found there is a return of stack address in function C_alloca
No, you did not.  See the definition of XNEWVEC.  C_alloca is not what most people understand to be alloca.
Comment 2 yuxuan He 2023-12-11 01:55:02 UTC
actually, i don't mean that XNEWVEC return a stack address, i mean "depth" is stack address and it has been store into new_storage
Comment 3 Alan Modra 2023-12-11 02:59:39 UTC
(In reply to yuxuan He from comment #2)
> actually, i don't mean that XNEWVEC return a stack address, i mean "depth"
> is stack address and it has been store into new_storage
That too is not a problem.  Given "char *p = C_alloca (size)", any access outside the range [p, p+size) is undefined behaviour.
Comment 4 yuxuan He 2023-12-11 03:04:08 UTC
ok thanks