* [PATCH] jit: avoid calloc() poisoning on musl [PR106102]
@ 2022-06-27 22:58 Sergei Trofimovich
2022-06-28 7:02 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Sergei Trofimovich @ 2022-06-27 22:58 UTC (permalink / raw)
To: gcc-patches; +Cc: rguenth, dmalcolm, Sergei Trofimovich
From: Sergei Trofimovich <siarheit@google.com>
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 sys-specific header before "system.h" inclusion
to evade poisoning.
gcc/jit/
PR c++/106102
* jit-playback.cc: Include <pthread.h> before "system.h" to avoid calloc()
poisoning.
* jit-recording.cc: Ditto.
* libgccjit.cc: Ditto.
---
gcc/jit/jit-playback.cc | 5 +++--
gcc/jit/jit-recording.cc | 4 +++-
gcc/jit/libgccjit.cc | 4 +++-
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 6be6bdf8dea..4ab7b59cab9 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -19,6 +19,9 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+/* <pthread.h> has to go before "system.h" as it pull in to-be-poisoned
+ symbols on musl like calloc(). */
+#include <pthread.h>
#include "system.h"
#include "coretypes.h"
#include "target.h"
@@ -41,8 +44,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"
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 697dee66e73..9505ed3b279 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -19,13 +19,15 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+/* <pthread.h> has to go before "system.h" as it pull in to-be-poisoned
+ symbols on musl like calloc(). */
+#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"
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 0e76097b4ba..6a0ac8aaba2 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -19,12 +19,14 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+/* <pthread.h> has to go before "system.h" as it pull in to-be-poisoned
+ symbols on musl like calloc(). */
+#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"
--
2.36.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] jit: avoid calloc() poisoning on musl [PR106102]
2022-06-27 22:58 [PATCH] jit: avoid calloc() poisoning on musl [PR106102] Sergei Trofimovich
@ 2022-06-28 7:02 ` Richard Biener
2022-06-28 21:05 ` [PATCH v2] " Sergei Trofimovich
0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2022-06-28 7:02 UTC (permalink / raw)
To: Sergei Trofimovich; +Cc: gcc-patches, rguenth, dmalcolm, Sergei Trofimovich
On Mon, 27 Jun 2022, Sergei Trofimovich wrote:
> From: Sergei Trofimovich <siarheit@google.com>
>
> 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 sys-specific header before "system.h" inclusion
> to evade poisoning.
>
> gcc/jit/
>
> PR c++/106102
> * jit-playback.cc: Include <pthread.h> before "system.h" to avoid calloc()
> poisoning.
> * jit-recording.cc: Ditto.
> * libgccjit.cc: Ditto.
> ---
> gcc/jit/jit-playback.cc | 5 +++--
> gcc/jit/jit-recording.cc | 4 +++-
> gcc/jit/libgccjit.cc | 4 +++-
> 3 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
> index 6be6bdf8dea..4ab7b59cab9 100644
> --- a/gcc/jit/jit-playback.cc
> +++ b/gcc/jit/jit-playback.cc
> @@ -19,6 +19,9 @@ along with GCC; see the file COPYING3. If not see
> <http://www.gnu.org/licenses/>. */
>
> #include "config.h"
> +/* <pthread.h> has to go before "system.h" as it pull in to-be-poisoned
> + symbols on musl like calloc(). */
> +#include <pthread.h>
there are probably targets where there need to be some #includes before
including pthread.h which means it would be best to include pthread.h
from within system.h (conditional, of course, just add a
INCLUDE_PTHREAD_H preprocessor guard).
Richard.
> #include "system.h"
> #include "coretypes.h"
> #include "target.h"
> @@ -41,8 +44,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"
> diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
> index 697dee66e73..9505ed3b279 100644
> --- a/gcc/jit/jit-recording.cc
> +++ b/gcc/jit/jit-recording.cc
> @@ -19,13 +19,15 @@ along with GCC; see the file COPYING3. If not see
> <http://www.gnu.org/licenses/>. */
>
> #include "config.h"
> +/* <pthread.h> has to go before "system.h" as it pull in to-be-poisoned
> + symbols on musl like calloc(). */
> +#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"
> diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
> index 0e76097b4ba..6a0ac8aaba2 100644
> --- a/gcc/jit/libgccjit.cc
> +++ b/gcc/jit/libgccjit.cc
> @@ -19,12 +19,14 @@ along with GCC; see the file COPYING3. If not see
> <http://www.gnu.org/licenses/>. */
>
> #include "config.h"
> +/* <pthread.h> has to go before "system.h" as it pull in to-be-poisoned
> + symbols on musl like calloc(). */
> +#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"
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstra
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] jit: avoid calloc() poisoning on musl [PR106102]
2022-06-28 7:02 ` Richard Biener
@ 2022-06-28 21:05 ` Sergei Trofimovich
2022-06-29 6:54 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Sergei Trofimovich @ 2022-06-28 21:05 UTC (permalink / raw)
To: gcc-patches; +Cc: rguenth, dmalcolm, Sergei Trofimovich
From: Sergei Trofimovich <siarheit@google.com>
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.
---
gcc/jit/jit-playback.cc | 3 +--
gcc/jit/jit-recording.cc | 2 +-
gcc/jit/libgccjit.cc | 2 +-
gcc/system.h | 4 ++++
4 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 6be6bdf8dea..79714132b91 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -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"
@@ -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"
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 697dee66e73..f78daed2d71 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -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"
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 0e76097b4ba..ca862662777 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -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"
diff --git a/gcc/system.h b/gcc/system.h
index 67158b70c78..f8d42ff6815 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -753,6 +753,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>
--
2.36.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] jit: avoid calloc() poisoning on musl [PR106102]
2022-06-28 21:05 ` [PATCH v2] " Sergei Trofimovich
@ 2022-06-29 6:54 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-06-29 6:54 UTC (permalink / raw)
To: Sergei Trofimovich; +Cc: gcc-patches, rguenth, dmalcolm, Sergei Trofimovich
> Am 28.06.2022 um 23:06 schrieb Sergei Trofimovich <slyich@gmail.com>:
>
> From: Sergei Trofimovich <siarheit@google.com>
>
> 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.
Ok,
Thanks,
Richard
> 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.
> ---
> gcc/jit/jit-playback.cc | 3 +--
> gcc/jit/jit-recording.cc | 2 +-
> gcc/jit/libgccjit.cc | 2 +-
> gcc/system.h | 4 ++++
> 4 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
> index 6be6bdf8dea..79714132b91 100644
> --- a/gcc/jit/jit-playback.cc
> +++ b/gcc/jit/jit-playback.cc
> @@ -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"
> @@ -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"
> diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
> index 697dee66e73..f78daed2d71 100644
> --- a/gcc/jit/jit-recording.cc
> +++ b/gcc/jit/jit-recording.cc
> @@ -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"
> diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
> index 0e76097b4ba..ca862662777 100644
> --- a/gcc/jit/libgccjit.cc
> +++ b/gcc/jit/libgccjit.cc
> @@ -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"
> diff --git a/gcc/system.h b/gcc/system.h
> index 67158b70c78..f8d42ff6815 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -753,6 +753,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>
> --
> 2.36.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-29 6:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 22:58 [PATCH] jit: avoid calloc() poisoning on musl [PR106102] Sergei Trofimovich
2022-06-28 7:02 ` Richard Biener
2022-06-28 21:05 ` [PATCH v2] " Sergei Trofimovich
2022-06-29 6:54 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).