What is #pragma textflag 7

129 views
Skip to first unread message

unread,
Oct 12, 2012, 12:09:13 PM10/12/12
to golan...@googlegroups.com
Hello. In the C source code there are instance of:

#pragma textflag 7
void function() {...}

I would like to know how is this implemented, and what is the stack capacity in the body of the function.

minux

unread,
Oct 12, 2012, 12:24:54 PM10/12/12
to ⚛, golan...@googlegroups.com
basically it means the function is not split-stack function, that is, the linker shouldn't
add stack split instruction prolog to it, and it can only use very limited stack space.
(120 bytes maximum stack space of consecutive non-stack-split functions in a row)

these defines expressed the detailed meaning of each bit of textflag (dataflag)
#define NOPROF  (1<<0)
#define DUPOK   (1<<1)
#define NOSPLIT (1<<2)
#define RODATA  (1<<3)
(taken from cmd/6l/6.out.h)

unread,
Oct 12, 2012, 12:38:36 PM10/12/12
to golan...@googlegroups.com, ⚛
On Friday, October 12, 2012 6:25:16 PM UTC+2, minux wrote:

On Sat, Oct 13, 2012 at 12:09 AM, ⚛ <0xe2.0x...@gmail.com> wrote:
Hello. In the C source code there are instance of:

#pragma textflag 7
void function() {...}

I would like to know how is this implemented, and what is the stack capacity in the body of the function.
basically it means the function is not split-stack function, that is, the linker shouldn't
add stack split instruction prolog to it, and it can only use very limited stack space.

The compiler is verifying the 120 bytes constraint by computing the stack size of the function and by making sure there are no recursive function calls and no function calls through a pointer?

minux

unread,
Oct 12, 2012, 12:46:49 PM10/12/12
to ⚛, golan...@googlegroups.com
On Sat, Oct 13, 2012 at 12:38 AM, ⚛ <0xe2.0x...@gmail.com> wrote:
The compiler is verifying the 120 bytes constraint by computing the stack size of the function and by making sure there are no recursive function calls and no function calls through a pointer?
cmd/6l will verify this.
recursive function won't work, but calling a function pointer is allowed (because no check can be done)
and it is a known workaround for the check.

Russ Cox

unread,
Oct 12, 2012, 2:41:42 PM10/12/12
to ⚛, golan...@googlegroups.com
> The compiler is verifying the 120 bytes constraint by computing the stack
> size of the function and by making sure there are no recursive function
> calls and no function calls through a pointer?

Yes, the linker verifies this. There is an assumption that any function pointer
called by a textflag 7 function is a function with a stack overflow
check (textflag 0).

Russ
Reply all
Reply to author
Forward
0 new messages