Reputation: 1
How to disable reentrant functions and multithreading using gcc flags? I tried with -D_REENTRANT, -U_REENTRANT, -D_REENT_ONLY, etc. it didn't help. Or should i change anything in LDFLAGS also? Untill now, I have only tried changing CFLAGS. PS: I am building for a baremetal environment and the _impure_ptr is messing up with my load addresses.
Upvotes: -2
Views: 43
Reputation: 27210
My previous comment (now deleted) was unhelpful. I apologize for typing before thinking.
In general, there is no such thing as a compiler flag to "disable reentrancy." That wouldn't make any sense. There is no -D_REENTRANT
flag or anything like.
There is a -D
name flag where name can be any valid pre-processor symbol. In your example, the name is _REENTRANT
. When you compile a source file with -D_REENTRANT
, the compiler will treat the file as if the file began with the line #define _REENTRANT
. Similarly, compiling with -U_REENTRANT
on the command line is equivalent to compiling a file that begins with #undef _REENTRANT
.
So, what does #define _REENTRANT
or #undef _REENTRANT
mean? That depends entirely on the source code file that you are compiling. The -D
and -U
flags allow you to invoke conditional compilation *IF* the source file is designed for conditional compilation. "Conditional compilation" refers to a technique in which a single source code file can produce several, slightly different object code modules depending on what flags were specified.
If the project that you are compiling contains lines like #ifdef _REENTRANT
or #if defined(_REENTRANT)
then the program is likely to behave in different ways depending on whether or not the _REENTRANT
symbol is defined at compile time. If the program contains no mention of _REENTRANT
, then -D_REENTRANT
or -U_REENTRANT
will have no effect.
To find out what conditional compilation options are available, your first step should be to read the documentation for the library that you are trying to build. Look especially for anything that talks about how to configure the library, or how to build and install the library.
You also could examine the code, and search for any #if
or #ifdef
or #ifndef
lines. Read the conditional code, to get a sense of what it does differently. But beware! Some conditional flags might not be intended for you to use:
They could enable obsolete/broken code, left over from some older project,
They could enable debugging behaviors that were exploited by the project's developers, and, (maybe most important of all),
They could be intended for use by some automatic configuration tool (e.g., GNU autoconf) that probes your system to discover what features are available, and which then writes the scripts that you are supposed to use to build the library in a way that is compatible with those features.
Upvotes: 0