Skip to content

Commit

Permalink
jit: avoid calloc() poisoning on musl [PR106102]
Browse files Browse the repository at this point in the history
On musl <pthread.h> uses calloc() (via <sched.h>). jit/ includes
it directly and exposes use of poisoned calloc():

    /build/build/./prev-gcc/xg++ ... ../../gcc-13-20220626/gcc/jit/jit-playback.cc
    make[3]: *** [Makefile:1143: jit/libgccjit.o] Error 1
    make[3]: *** Waiting for unfinished jobs....
    In file included from /<<NIX>>/musl-1.2.3-dev/include/pthread.h:30,
                     from ../../gcc-13-20220626/gcc/jit/jit-playback.cc:44:
    /<<NIX>>/musl-1.2.3-dev/include/sched.h:84:7: error: attempt to use poisoned "calloc"
       84 | void *calloc(size_t, size_t);
          |       ^
    /<<NIX>>/musl-1.2.3-dev/include/sched.h:124:36: error: attempt to use poisoned "calloc"
      124 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
          |                                    ^

The change moves <pthread.h> inclusion to "system.h" under new
INCLUDE_PTHREAD_H guard and uses this mechanism in libgccjit.

gcc/

	PR c++/106102
	* system.h: Introduce INCLUDE_PTHREAD_H macros to include <pthread.h>.

gcc/jit/

	PR c++/106102
	* jit-playback.cc: Include <pthread.h> via "system.h" to avoid calloc()
	poisoning.
	* jit-recording.cc: Ditto.
	* libgccjit.cc: Ditto.

(cherry picked from commit 49d5080)
  • Loading branch information
trofi committed Jul 2, 2022
1 parent de6f402 commit ad5d760
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions gcc/jit/jit-playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */

#include "config.h"
#define INCLUDE_PTHREAD_H
#include "system.h"
#include "coretypes.h"
#include "target.h"
Expand All @@ -41,8 +42,6 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic.h"
#include "stmt.h"

#include <pthread.h>

#include "jit-playback.h"
#include "jit-result.h"
#include "jit-builtins.h"
Expand Down
2 changes: 1 addition & 1 deletion gcc/jit/jit-recording.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */

#include "config.h"
#define INCLUDE_PTHREAD_H
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "pretty-print.h"
#include "toplev.h"

#include <pthread.h>

#include "jit-builtins.h"
#include "jit-recording.h"
Expand Down
2 changes: 1 addition & 1 deletion gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */

#include "config.h"
#define INCLUDE_PTHREAD_H
#include "system.h"
#include "coretypes.h"
#include "timevar.h"
#include "typed-splay-tree.h"
#include "cppbuiltin.h"
#include <pthread.h>

#include "libgccjit.h"
#include "jit-recording.h"
Expand Down
4 changes: 4 additions & 0 deletions gcc/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ extern int vsnprintf (char *, size_t, const char *, va_list);
#endif
#endif

#ifdef INCLUDE_PTHREAD_H
#include <pthread.h>
#endif

#ifdef INCLUDE_ISL
#ifdef HAVE_isl
#include <isl/options.h>
Expand Down

0 comments on commit ad5d760

Please sign in to comment.