Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC error message: attempt to use poisoned "TARGET_I386"

Tags:

c

gcc

I'm modifying Qemu's source code, created a file like this

#if defined(TARGET_I386)
    /* some defines */
#elif defined(TARGET_ARM)
    /* some other defines */
#endif

This file is then included in vl.c, and gcc reports the following error message:

error: attempt to use poisoned "TARGET_I386"
error: attempt to use poisoned "TARGET_ARM"

TARGET_I386 is defined in another header file and is used in other qemu's source file.

What's the meaning of this error message?

Update:

As mentioned by Matthias Werner, these defines should not be used for target independent code. These poison identifies are defined in poison.h

like image 513
cyfdecyf Avatar asked Feb 27 '12 07:02

cyfdecyf


2 Answers

Apparently the identifiers have been marked as poisoned

From GCC Documentation

#pragma GCC poison

Sometimes, there is an identifier that you want to remove completely from your program, and make sure that it never creeps back in. To enforce this, you can poison the identifier with this pragma. #pragma GCC poison is followed by a list of identifiers to poison. If any of those identifiers appears anywhere in the source after the directive, it is a hard error.

For example,

#pragma GCC poison printf sprintf fprintf
sprintf(some_string, "hello");

will produce an error.

If a poisoned identifier appears as part of the expansion of a macro which was defined before the identifier was poisoned, it will not cause an error. This lets you poison an identifier without worrying about system headers defining macros that use it.

For example,

#define strrchr rindex
#pragma GCC poison rindex
strrchr(some_string, 'h');

will not produce an error.

like image 117
r_ahlskog Avatar answered Nov 15 '22 16:11

r_ahlskog


Poison identifiers in QEMU should not be used when building target independent code.

like image 42
Matthias Avatar answered Nov 15 '22 16:11

Matthias