Discussion:
Strange behaviour of gcc
f***@tiscali.it
2002-12-23 22:51:42 UTC
Permalink
Can somebody explain why gcc (version 3.2 20020927) on Cygwin does this?
Type this simple C program

void func(void){
struct {unsigned char data[3985];}var;
}

and compile with

gcc -c filename.c

Then type

nm filename.o

The output is

00000000 b .bss
00000000 d .data
00000000 t .text
U __alloca
00000000 T _func

Why on earth is the symbol __alloca doing there?

Just change the program to

void func(void){
struct {unsigned char data[3984];}var;
}

and compile it. This time, nm's output is

00000000 b .bss
00000000 d .data
00000000 t .text
00000000 T _func

as it should. Is there a reason why the symbol __alloca appears?

__________________________________________________________________
Tiscali ADSL. Scopri la fantastica promozione di Natale: tutto Gratis fino
al 9 gennaio!
Abbonati ora: prima ti abboni, piĆ¹ risparmi!
http://point.tiscali.it/adsl/index.shtml
Max Bowsher
2002-12-23 23:25:00 UTC
Permalink
Post by f***@tiscali.it
Can somebody explain why gcc (version 3.2 20020927) on Cygwin does
this? Type this simple C program
void func(void){
struct {unsigned char data[3985];}var;
}
and compile with
gcc -c filename.c
Then type
nm filename.o
The output is
00000000 b .bss
00000000 d .data
00000000 t .text
U __alloca
00000000 T _func
Why on earth is the symbol __alloca doing there?
Just change the program to
void func(void){
struct {unsigned char data[3984];}var;
}
and compile it. This time, nm's output is
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 T _func
as it should. Is there a reason why the symbol __alloca appears?
Yes. Gcc's optimizer chose to make a large amount of local variable
allocation into an alloca call.

Does it matter?

Max.
f***@tiscali.it
2002-12-29 10:38:43 UTC
Permalink
-- Messaggio Originale --
Subject: Re: Strange behaviour of gcc
Date: Mon, 23 Dec 2002 23:25:00 -0000
Post by f***@tiscali.it
Can somebody explain why gcc (version 3.2 20020927) on Cygwin does
this?
Yes. Gcc's optimizer chose to make a large amount of local variable
allocation into an alloca call.
Does it matter?
For what I'm trying to do, it does. I would like to build a DLL which is
not linked to the C runtime library in order to have a smaller file (a trick
copied from Winamp plug-ins), and I don't mind about sub-optimal performance.
The executable dlopen()s the DLL and provides some callbacks to it.

If the DLL is linked to CRT, it is 20KB long. If it is not, it is 8KB long
(but obviously it does not have alloca available).

Is there a gcc option to build code without the call to alloca?

__________________________________________________________________
Tiscali ADSL: abbonati entro il 31 gennaio.
Non paghi l'attivazione.
Non paghi il primo mese.
http://www.tiscali.it/adsl
Danny Smith
2002-12-24 05:11:34 UTC
Permalink
Post by f***@tiscali.it
Can somebody explain why gcc (version 3.2 20020927) on Cygwin does
this? Type this simple C program
void func(void){
struct {unsigned char data[3985];}var;
}
and compile with
gcc -c filename.c
Then type
nm filename.o
The output is
00000000 b .bss
00000000 d .data
00000000 t .text
U __alloca
00000000 T _func
Why on earth is the symbol __alloca doing there?
Just change the program to
void func(void){
struct {unsigned char data[3984];}var;
}
and compile it. This time, nm's output is
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 T _func
as it should. Is there a reason why the symbol __alloca appears?
GCC's __builtin_alloca uses a helper function called _alloca to check the stack
whenever allocating more that 4000 bytes in one go.

Danny

http://movies.yahoo.com.au - Yahoo! Movies
- What's on at your local cinema?
f***@tiscali.it
2002-12-24 15:21:26 UTC
Permalink
-- Messaggio Originale --
Date: Tue, 24 Dec 2002 16:11:34 +1100 (EST)
Subject: Re:Strange behaviour of gcc
Post by f***@tiscali.it
Is there a reason why the symbol __alloca appears?
GCC's __builtin_alloca uses a helper function called _alloca to check the stack
whenever allocating more that 4000 bytes in one go.
Thanks a lot Danny. Is there a way to avoid that? I tried -fno-builtin,
but it didn't seem to work (__alloca is still there).

Fabrizio

__________________________________________________________________
Tiscali ADSL: abbonati entro il 31 gennaio.
Non paghi l'attivazione.
Non paghi il primo mese.
http://www.tiscali.it/adsl
Randall R Schulz
2002-12-24 16:16:59 UTC
Permalink
Fabrizio,

Now we're back to Max's question: Why does it matter to you?

Stack space is usually far more limited than heap space, which I assume is
what motivates this behavior in the code generator. The programming
language's semantics are maintained. And I challenge you to show a
performance problem because some heap allocations are involved.

Randall Schulz
Post by f***@tiscali.it
-- Messaggio Originale --
Date: Tue, 24 Dec 2002 16:11:34 +1100 (EST)
Subject: Re:Strange behaviour of gcc
Post by f***@tiscali.it
Is there a reason why the symbol __alloca appears?
GCC's __builtin_alloca uses a helper function called _alloca to check
the stack whenever allocating more that 4000 bytes in one go.
Thanks a lot Danny. Is there a way to avoid that? I tried -fno-builtin,
but it didn't seem to work (__alloca is still there).
Fabrizio
f***@tiscali.it
2002-12-28 20:11:01 UTC
Permalink
From: Randall R Schulz <rrschulz at cris dot com>
To: cygwin at cygwin dot com
Date: Tue, 24 Dec 2002 08:16:59 -0800
Subject: Re:Strange behaviour of gcc
Post by Randall R Schulz
Stack space is usually far more limited than heap
space, which I assume is what motivates this behavior
in the code generator. The programming language's
semantics are maintained.
What I would like to do is to build a DLL which does not link to the C runtime
library (and therefore it does not have access to _alloca or other CRT functions).
The executable dynamically loads the DLL with dlopen() and the DLL calls
some callback functions provided by the executable. The DLL's size is about
20KB if it links to CRT, 8KB if it does not. The main motivation is to have
a small file.

So, is there a gcc option which allows not to call _alloca (even if the
performance is sub-optimal)?

Regards
Fabrizio

__________________________________________________________________
Tiscali ADSL: abbonati entro il 31 gennaio.
Non paghi l'attivazione.
Non paghi il primo mese.
http://www.tiscali.it/adsl
Danny Smith
2002-12-29 20:28:12 UTC
Permalink
Post by Danny Smith
GCC's __builtin_alloca uses a helper function called _alloca to check the
stack
whenever allocating more that 4000 bytes in one go.
Danny
To disable stack probing, add this switch -mno-stack-arg-probe.

Danny

http://movies.yahoo.com.au - Yahoo! Movies
- What's on at your local cinema?
Randall R Schulz
2002-12-30 00:24:06 UTC
Permalink
Danny,

Man! I scanned through the GCC man page for anything that would control
this action, and couldn't find anything. I don't see "-mno-stack-arg-probe"
listed there at all, nor is any option that includes the word "probe."

Google ("GCC mno-stack-arg-probe"
<http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=GCC+mno-stack-arg-probe&btnG=Google+Search>)
turns up only three relevant hits (including one recent thread on the
Cygwin mailing list:
<http://www.cygwin.com/ml/cygwin/2002-06/msg00122.html> and
<http://www.cygwin.com/ml/cygwin/2002-06/msg00123.html>).

Randall Schulz
Post by Danny Smith
Post by Danny Smith
GCC's __builtin_alloca uses a helper function called _alloca to check
the stack whenever allocating more that 4000 bytes in one go.
Danny
To disable stack probing, add this switch -mno-stack-arg-probe.
Danny
Danny Smith
2002-12-30 01:38:11 UTC
Permalink
Hello Randall

Yeah, no documentation to speak of. The only reason I know about it because
I've been chasing the _alloca bug that Fish reported. It is still present in
GCC trunk (3.4). I have submitted a simple patch that fixes, but ... time for
a ping in the New Year.

Danny,


rrschulz wrote:

Man! I scanned through the GCC man page for anything that would control this

action, and couldn't find anything. I don't see "-mno-stack-arg-probe" listed
there at all, nor is any option that includes the word "probe."

Google ("GCC mno-stack-arg-probe"
<http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=GCC+mno-stack-arg-probe&btnG=Google+Search>)
turns up only three relevant hits (including one recent thread on the Cygwin
mailing list: <http://www.cygwin.com/ml/cygwin/2002-06/msg00122.html> and
<http://www.cygwin.com/ml/cygwin/2002-06/msg00123.html>).

Randall Schulz

http://movies.yahoo.com.au - Yahoo! Movies
- What's on at your local cinema?

Loading...