tengine jemalloc's configure script's compiler detection is problematic

vmjh9lq9  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(43)

Ⅰ. Issue Description

The configure script printed the following error message while building Tengine:

Ⅱ. Describe what happened

checking for jemalloc library ... found
auto/lib/jemalloc/conf: line 36: [: too many arguments
creating objs/Makefile

The corresponding part of the code looks like this:

tengine/auto/lib/jemalloc/conf

Lines 35 to 40 in ae3ff46

| | if [ $ngx_found = yes ]; then |
| | if [ $CC = gcc ]; then |
| | CFLAGS="$CFLAGS -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free" |
| | fi |
| | CORE_LIBS="$CORE_LIBS $ngx_feature_libs" |
| | JEMALLOC=YES |

The $CC = gcc conditional expression has the following errors:

  • The CC environment variable may contain spaces, e.g. when using CCache ( CC='ccache gcc' ) or distcc
  • The check doesn't verify the case where the compiler command has invoked gcc indirectly(refer to the CCache example above).

Ⅲ. Describe what you expected to happen

IMO the compiler check should be fixed by checking the invoked program's specific characteristics(e.g. gcc --version ) instead of simply comparing the command name.

Also, the CC environment variable should be wrapped with double quotes, as it may contain space characters.

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. Install jemalloc build dependencies and CCache
  2. Run the configure program with CC environment variable set to ccache gcc

Ⅴ. Anything else we need to know?

N/A

Ⅵ. Environment:

  • Tengine version (use sbin/nginx -V ): 2.3.3
  • OS (e.g. from /etc/os-release): Ubuntu 21.04 AMD64
  • Kernel (e.g. uname -a ): 5.11.0-17-generic
ao218c7q

ao218c7q1#

I made a patch that fixes the problem, however I currently unable to send a pull request:

Fix jemalloc compiler check

Fixes #1560.

diff --recursive --unified --ignore-space-change tengine-2.3.3/auto/lib/jemalloc/conf tengine-2.3.3.patched/auto/lib/jemalloc/conf
--- tengine-2.3.3/auto/lib/jemalloc/conf	2021-03-29 15:19:12.000000000 +0800
+++ tengine-2.3.3.patched/auto/lib/jemalloc/conf	2021-05-24 12:58:39.734911464 +0800
@@ -33,7 +33,7 @@
 
 
         if [ $ngx_found = yes ]; then
-            if [ $CC = gcc ]; then
+            if $CC -v | grep -cq gcc; then
                 CFLAGS="$CFLAGS -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free"
             fi        
             CORE_LIBS="$CORE_LIBS $ngx_feature_libs"

相关问题