Skip to content

Commit

Permalink
Merge branch 'mcount-nofp'
Browse files Browse the repository at this point in the history
Fix crash of clang compiler when building uftrace source for x86-64.
The -mno-sse2 option can cause an internal compiler error when used
with floating-point types.  Clang folks suggested -mgeneral-regs-only
option, so let's use it instead.

Also change libmcount not to generate instructions that use floating-
point type in the common code (under utils/ directory).

Fixed: #1877

Signed-off-by: Namhyung Kim <[email protected]>
  • Loading branch information
namhyung committed Jan 23, 2024
2 parents ad1dd38 + 79a09af commit 3609b18
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ BENCH_CFLAGS = -D_GNU_SOURCE -g -pg $(CFLAGS_$@) $(CFLAGS_bench)
TRACEEVENT_CFLAGS = $(COMMON_CFLAGS) $(CFLAGS_$@) $(CFLAGS_traceevent)
LIB_CFLAGS = $(COMMON_CFLAGS) $(CFLAGS_$@) $(CFLAGS_lib)
LIB_CFLAGS += -fPIC -fvisibility=hidden -fno-omit-frame-pointer
LIB_CFLAGS += -fno-builtin -fno-tree-vectorize
LIB_CFLAGS += -fno-builtin -fno-tree-vectorize -DLIBMCOUNT
TEST_CFLAGS = $(COMMON_CFLAGS) -DUNIT_TEST
PYTHON_CFLAGS = $(COMMON_CFLAGS) -fPIC

Expand Down
6 changes: 4 additions & 2 deletions check-deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ CHECK_LIST += have_libunwind
CHECK_LIST += have_libcapstone
CHECK_LIST += cc_has_minline_all_stringops
CHECK_LIST += have_libtraceevent
CHECK_LIST += cc_has_mgeneral_regs_only

#
# This is needed for checking build dependency
#

CHECK_CFLAGS = $(CFLAGS) $(CFLAGS_$@) -Werror
CHECK_CFLAGS = $(CFLAGS) $(CFLAGS_$@) -O2 -Werror
CHECK_LDFLAGS = $(LDFLAGS) $(LDFLAGS_$@)

# libpython3 provides an embed version of pkg-config file since python3.8
Expand All @@ -37,7 +38,7 @@ endif
CFLAGS_cc_has_mfentry = -mfentry
LDFLAGS_cxa_demangle = -lstdc++
LDFLAGS_have_libelf = -lelf
CFLAGS_cc_has_mno_sse2 = -O2 -mno-sse -mno-sse2
CFLAGS_cc_has_mno_sse2 = -mno-sse -mno-sse2
LDFLAGS_have_libpython2.7 = -lpython2.7
CFLAGS_have_libpython3 = $(shell pkg-config python3$(EMBED) --cflags 2> /dev/null)
LDFLAGS_have_libpython3 = $(shell pkg-config python3$(EMBED) --libs 2> /dev/null)
Expand All @@ -54,6 +55,7 @@ LDFLAGS_have_libunwind = $(shell pkg-config --libs libunwind 2> /dev/null)
CFLAGS_cc_has_minline_all_stringops = -minline-all-stringops
CFLAGS_have_libtraceevent = $(shell pkg-config --cflags libtraceevent 2> /dev/null)
LDFLAGS_have_libtraceevent = $(shell pkg-config --libs libtraceevent 2> /dev/null)
CFLAGS_cc_has_mgeneral_regs_only = -mgeneral-regs-only

check-build: $(CHECK_LIST)

Expand Down
4 changes: 3 additions & 1 deletion check-deps/Makefile.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ ifneq ($(wildcard $(objdir)/check-deps/cxa_demangle),)
COMMON_LDFLAGS += -lstdc++
endif

ifneq ($(wildcard $(objdir)/check-deps/cc_has_mno_sse2),)
ifneq ($(wildcard $(objdir)/check-deps/cc_has_mgeneral_regs_only),)
LIB_CFLAGS += -mgeneral-regs-only
else ifneq ($(wildcard $(objdir)/check-deps/cc_has_mno_sse2),)
LIB_CFLAGS += -mno-sse -mno-sse2
endif

Expand Down
7 changes: 7 additions & 0 deletions check-deps/__cc_has_mgeneral_regs_only.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main(void)
{
printf("%f", 123.45);
return 0;
}
2 changes: 2 additions & 0 deletions utils/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ void __pr_color(char code, const char *fmt, ...)
color(ec, outfp);
}

#ifndef LIBMCOUNT
static void __print_time_unit(int64_t delta_nsec, bool needs_sign)
{
uint64_t delta = llabs(delta_nsec);
Expand Down Expand Up @@ -441,3 +442,4 @@ void print_diff_count(uint64_t base, uint64_t pair)
else
pr_out("%9s", "+0");
}
#endif
4 changes: 3 additions & 1 deletion utils/script-luajit.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void setup_argument_context(bool is_retval, struct script_context *sc_ctx
unsigned short slen;
char ch_str[2];
char *str;
double dval;
double dval __maybe_unused;

/* skip unwanted arguments or retval */
if (is_retval != (spec->idx == RETVAL_IDX))
Expand Down Expand Up @@ -143,6 +143,7 @@ static void setup_argument_context(bool is_retval, struct script_context *sc_ctx
break;
case ARG_FMT_FLOAT:
memcpy(val.v, data, spec->size);
#ifndef LIBMCOUNT
switch (spec->size) {
case 4:
dval = val.f;
Expand All @@ -161,6 +162,7 @@ static void setup_argument_context(bool is_retval, struct script_context *sc_ctx
dllua_pushinteger(L, ++count);
dllua_pushnumber(L, dval);
dllua_settable(L, -3);
#endif
data += ALIGN(spec->size, 4);
break;

Expand Down
6 changes: 4 additions & 2 deletions utils/script-python.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static void insert_tuple_string(PyObject *tuple, int idx, char *v)
python_insert_tuple(tuple, 's', idx, val);
}

static void insert_tuple_double(PyObject *tuple, int idx, double v)
static void __maybe_unused insert_tuple_double(PyObject *tuple, int idx, double v)
{
union python_val val = {
.f = v,
Expand Down Expand Up @@ -429,7 +429,7 @@ static void setup_argument_context(PyObject **pDict, bool is_retval, struct scri
unsigned short slen;
char ch_str[2];
char *str;
double dval;
double dval __maybe_unused;

/* skip unwanted arguments or retval */
if (is_retval != (spec->idx == RETVAL_IDX))
Expand Down Expand Up @@ -468,6 +468,7 @@ static void setup_argument_context(PyObject **pDict, bool is_retval, struct scri

case ARG_FMT_FLOAT:
memcpy(val.v, data, spec->size);
#ifndef LIBMCOUNT
switch (spec->size) {
case 4:
dval = val.f;
Expand All @@ -484,6 +485,7 @@ static void setup_argument_context(PyObject **pDict, bool is_retval, struct scri
break;
}
insert_tuple_double(args, count++, dval);
#endif
data += ALIGN(spec->size, 4);
break;

Expand Down
3 changes: 3 additions & 0 deletions utils/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ union script_arg_val {
int i;
long l;
long long L;
/* libmcount should not access floating-point types. */
#ifndef LIBMCOUNT
float f;
double d;
long double D;
#endif
unsigned char v[16];
};

Expand Down

0 comments on commit 3609b18

Please sign in to comment.