Skip to content

Commit 35fab45

Browse files
author
Vladimir Mezentsev
committed
gprofng: 30360 Seg. Fault when application uses std::thread
We interpose a lot of libC functions (dlopen, fork, pthread_create, etc.). Some of these functions have versions. For example, % nm -D /lib64/gprofng/libgp-collector.so | grep thread_create@ | sort 000000000004b420 T pthread_create@GLIBC_2.34 000000000004b490 T pthread_create@GLIBC_2.17 000000000004b500 T pthread_create@GLIBC_2.2.5 000000000004b570 T pthread_create@GLIBC_2.1 000000000004b5e0 T pthread_create@GLIBC_2.0 Our library does not set the default version for symbols. This is correct because we don't know which libC will be used. gcc and g++ links differently the version symbols when the default version is not set. c-linker is using our pthread_create@GLIBC_2.34 and c++-linker is using our pthread_create@GLIBC_2.0 by default. The current implementation of the interposed functions is: If we are in our pthread_create@GLIBC_<NN>, we use dlvsym (dlflag, "pthread_create", "GLIBC_<NN>") to find and call the same function from libC. In the test from PR 30360, pthread_create@GLIBC_2.0 is not in the current libC. We need to call the default version symbol from libC. gprofng/ChangeLog 2023-04-16 Vladimir Mezentsev <[email protected]> PR gprofng/30360 * libcollector/iotrace.c: Find and call a default libC version symbol. * libcollector/dispatcher.c: Likewise. * libcollector/iotrace.c: Likewise. * libcollector/linetrace.c: Likewise. * libcollector/mmaptrace.c: Likewise. * libcollector/synctrace.c: Likewise. * libcollector/collector.h (REAL_DCL): Remove an unused argument.
1 parent 7a51575 commit 35fab45

File tree

6 files changed

+136
-94
lines changed

6 files changed

+136
-94
lines changed

gprofng/libcollector/collector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#else
5151
#define DCL_FUNC_VER(REAL_DCL, sym, ver) \
5252
SYMVER_ATTRIBUTE (__collector_ ## sym, ver) \
53-
REAL_DCL (__collector_ ## sym, CALL_REAL (sym))
53+
REAL_DCL (__collector_ ## sym)
5454
#endif
5555

5656
extern hrtime_t __collector_start_time;

gprofng/libcollector/dispatcher.c

+22-13
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,16 @@ init_interposition_intf ()
695695
__real_pthread_sigmask_2_17 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.17");
696696
__real_pthread_sigmask_2_2_5 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.2.5");
697697
__real_pthread_sigmask_2_0 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.0");
698-
__real_pthread_sigmask = dlsym (dlflag, "pthread_sigmask");
698+
if (__real_pthread_sigmask_2_32)
699+
__real_pthread_sigmask = __real_pthread_sigmask_2_32;
700+
else if (__real_pthread_sigmask_2_17)
701+
__real_pthread_sigmask = __real_pthread_sigmask_2_17;
702+
else if (__real_pthread_sigmask_2_2_5)
703+
__real_pthread_sigmask = __real_pthread_sigmask_2_2_5;
704+
else if (__real_pthread_sigmask_2_0)
705+
__real_pthread_sigmask = __real_pthread_sigmask_2_0;
706+
else
707+
__real_pthread_sigmask = dlsym (dlflag, "pthread_sigmask");
699708

700709
__real_pthread_create_2_34 = dlvsym (dlflag, "pthread_create", "GLIBC_2.34");
701710
__real_pthread_create_2_17 = dlvsym (dlflag, "pthread_create", "GLIBC_2.17");
@@ -922,20 +931,20 @@ gprofng_timer_create (int (real_func) (), clockid_t clockid,
922931
return -1;
923932
}
924933

925-
#define DCL_TIMER_CREATE(dcl_f, real_f) \
934+
#define DCL_TIMER_CREATE(dcl_f) \
926935
int dcl_f (clockid_t clockid, struct sigevent *sevp, timer_t *timerid) \
927936
{ \
928-
if ((real_f) == NULL) \
937+
if (__real_timer_create == NULL) \
929938
init_interposition_intf (); \
930-
return gprofng_timer_create (real_f, clockid, sevp, timerid); \
939+
return gprofng_timer_create (__real_timer_create, clockid, sevp, timerid); \
931940
}
932941

933942
DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_34, timer_create@GLIBC_2.34)
934943
DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_17, timer_create@GLIBC_2.17)
935944
DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_3_3, timer_create@GLIBC_2.3.3)
936945
DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_2_5, timer_create@GLIBC_2.2.5)
937946
DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_2, timer_create@GLIBC_2.2)
938-
DCL_TIMER_CREATE (timer_create, CALL_REAL (timer_create))
947+
DCL_TIMER_CREATE (timer_create)
939948

940949
/*------------------------------------------------------------- setitimer */
941950
int
@@ -1055,19 +1064,19 @@ gprofng_pthread_sigmask (int (real_func) (),
10551064

10561065
}
10571066

1058-
#define DCL_PTHREAD_SIGMASK(dcl_f, real_f) \
1067+
#define DCL_PTHREAD_SIGMASK(dcl_f) \
10591068
int dcl_f (int how, const sigset_t *iset, sigset_t* oset) \
10601069
{ \
1061-
if ((real_f) == NULL) \
1070+
if (__real_pthread_sigmask == NULL) \
10621071
init_interposition_intf (); \
1063-
return gprofng_pthread_sigmask (real_f, how, iset, oset); \
1072+
return gprofng_pthread_sigmask (__real_pthread_sigmask, how, iset, oset); \
10641073
}
10651074

10661075
DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_32, pthread_sigmask@GLIBC_2.32)
10671076
DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_17, pthread_sigmask@GLIBC_2.17)
10681077
DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_2_5, pthread_sigmask@GLIBC_2.2.5)
10691078
DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_0, pthread_sigmask@GLIBC_2.0)
1070-
DCL_PTHREAD_SIGMASK (pthread_sigmask, CALL_REAL(pthread_sigmask))
1079+
DCL_PTHREAD_SIGMASK (pthread_sigmask)
10711080

10721081
/*----------------------------------------------------------- pthread_create */
10731082
typedef struct _CollectorArgs
@@ -1154,21 +1163,21 @@ gprofng_pthread_create (int (real_func) (), pthread_t *thread,
11541163
}
11551164

11561165

1157-
#define DCL_PTHREAD_CREATE(dcl_f, real_f) \
1166+
#define DCL_PTHREAD_CREATE(dcl_f) \
11581167
int dcl_f (pthread_t *thread, const pthread_attr_t *attr, \
11591168
void *(*func)(void*), void *arg) \
11601169
{ \
1161-
if ((real_f) == NULL) \
1170+
if (__real_pthread_create == NULL) \
11621171
init_interposition_intf (); \
1163-
return gprofng_pthread_create (real_f, thread, attr, func, arg); \
1172+
return gprofng_pthread_create (__real_pthread_create, thread, attr, func, arg); \
11641173
}
11651174

11661175
DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_34, pthread_create@GLIBC_2.34)
11671176
DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_17, pthread_create@GLIBC_2.17)
11681177
DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_2_5, pthread_create@GLIBC_2.2.5)
11691178
DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_1, pthread_create@GLIBC_2.1)
11701179
DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_0, pthread_create@GLIBC_2.0)
1171-
DCL_PTHREAD_CREATE (pthread_create, CALL_REAL (pthread_create))
1180+
DCL_PTHREAD_CREATE (pthread_create)
11721181

11731182
int
11741183
__collector_ext_clone_pthread (int (*fn)(void *), void *child_stack, int flags, void *arg,

gprofng/libcollector/iotrace.c

+51-36
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,21 @@ init_io_intf ()
450450
else
451451
__real_fgetpos64 = dlsym (dlflag, "fgetpos64");
452452

453+
__real_fsetpos64_2_17 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.17");
454+
__real_fsetpos64_2_2_5 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.2.5");
455+
__real_fsetpos64_2_2 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.2");
456+
__real_fsetpos64_2_1 = dlvsym (dlflag, "fsetpos64", "GLIBC_2.1");
457+
if (__real_fsetpos64_2_17)
458+
__real_fsetpos64 = __real_fsetpos64_2_17;
459+
else if (__real_fsetpos64_2_2_5)
460+
__real_fsetpos64 = __real_fsetpos64_2_2_5;
461+
else if (__real_fsetpos64_2_2)
462+
__real_fsetpos64 = __real_fsetpos64_2_2;
463+
else if (__real_fsetpos64_2_1)
464+
__real_fsetpos64 = __real_fsetpos64_2_1;
465+
else
466+
__real_fsetpos64 = dlsym (dlflag, "fsetpos64");
467+
453468
__real_pread_2_2 = dlvsym (dlflag, "pread", "GLIBC_2.2");
454469
if (__real_pread_2_2)
455470
__real_pread = __real_pread_2_2;
@@ -1001,21 +1016,21 @@ gprofng_open64 (int(real_open64) (const char *, int, ...),
10011016
return fd;
10021017
}
10031018

1004-
#define DCL_OPEN64(dcl_f, real_f) \
1019+
#define DCL_OPEN64(dcl_f) \
10051020
int dcl_f (const char *path, int oflag, ...) \
10061021
{ \
1007-
if ((real_f) == NULL) \
1022+
if (__real_open64 == NULL) \
10081023
init_io_intf (); \
10091024
mode_t mode; \
10101025
va_list ap; \
10111026
va_start (ap, oflag); \
10121027
mode = va_arg (ap, mode_t); \
10131028
va_end (ap); \
1014-
return gprofng_open64 (real_f, path, oflag, mode); \
1029+
return gprofng_open64 (__real_open64, path, oflag, mode); \
10151030
}
10161031

10171032
DCL_FUNC_VER (DCL_OPEN64, open64_2_2, open64@GLIBC_2.2)
1018-
DCL_OPEN64 (open64, CALL_REAL(open64))
1033+
DCL_OPEN64 (open64)
10191034

10201035

10211036
#define F_ERROR_ARG 0
@@ -1516,19 +1531,19 @@ gprofng_fopen (FILE*(real_fopen) (), const char *filename, const char *mode)
15161531
return fp;
15171532
}
15181533

1519-
#define DCL_FOPEN(dcl_f, real_f) \
1534+
#define DCL_FOPEN(dcl_f) \
15201535
FILE *dcl_f (const char *filename, const char *mode) \
15211536
{ \
1522-
if ((real_f) == NULL) \
1537+
if (__real_fopen == NULL) \
15231538
init_io_intf (); \
1524-
return gprofng_fopen (real_f, filename, mode); \
1539+
return gprofng_fopen (__real_fopen, filename, mode); \
15251540
}
15261541

15271542
DCL_FUNC_VER (DCL_FOPEN, fopen_2_17, fopen@GLIBC_2.17)
15281543
DCL_FUNC_VER (DCL_FOPEN, fopen_2_2_5, fopen@GLIBC_2.2.5)
15291544
DCL_FUNC_VER (DCL_FOPEN, fopen_2_1, fopen@GLIBC_2.1)
15301545
DCL_FUNC_VER (DCL_FOPEN, fopen_2_0, fopen@GLIBC_2.0)
1531-
DCL_FOPEN (fopen, CALL_REAL(fopen))
1546+
DCL_FOPEN (fopen)
15321547

15331548
/*------------------------------------------------------------- fclose */
15341549
static int
@@ -1564,19 +1579,19 @@ gprofng_fclose (int(real_fclose) (), FILE *stream)
15641579
return stat;
15651580
}
15661581

1567-
#define DCL_FCLOSE(dcl_f, real_f) \
1582+
#define DCL_FCLOSE(dcl_f) \
15681583
int dcl_f (FILE *stream) \
15691584
{ \
1570-
if ((real_f) == NULL) \
1585+
if (__real_fclose == NULL) \
15711586
init_io_intf (); \
1572-
return gprofng_fclose (real_f, stream); \
1587+
return gprofng_fclose (__real_fclose, stream); \
15731588
}
15741589

15751590
DCL_FUNC_VER (DCL_FCLOSE, fclose_2_17, fclose@GLIBC_2.17)
15761591
DCL_FUNC_VER (DCL_FCLOSE, fclose_2_2_5, fclose@GLIBC_2.2.5)
15771592
DCL_FUNC_VER (DCL_FCLOSE, fclose_2_1, fclose@GLIBC_2.1)
15781593
DCL_FUNC_VER (DCL_FCLOSE, fclose_2_0, fclose@GLIBC_2.0)
1579-
DCL_FCLOSE (fclose, CALL_REAL(fclose))
1594+
DCL_FCLOSE (fclose)
15801595

15811596
/*------------------------------------------------------------- fflush */
15821597
int
@@ -1653,19 +1668,19 @@ gprofng_fdopen (FILE*(real_fdopen) (), int fildes, const char *mode)
16531668
return fp;
16541669
}
16551670

1656-
#define DCL_FDOPEN(dcl_f, real_f) \
1671+
#define DCL_FDOPEN(dcl_f) \
16571672
FILE *dcl_f (int fildes, const char *mode) \
16581673
{ \
1659-
if ((real_f) == NULL) \
1674+
if (__real_fdopen == NULL) \
16601675
init_io_intf (); \
1661-
return gprofng_fdopen (real_f, fildes, mode); \
1676+
return gprofng_fdopen (__real_fdopen, fildes, mode); \
16621677
}
16631678

16641679
DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_17, fdopen@GLIBC_2.17)
16651680
DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_2_5, fdopen@GLIBC_2.2.5)
16661681
DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_1, fdopen@GLIBC_2.1)
16671682
DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_0, fdopen@GLIBC_2.0)
1668-
DCL_FDOPEN (fdopen, CALL_REAL(fdopen))
1683+
DCL_FDOPEN (fdopen)
16691684

16701685
/*------------------------------------------------------------- dup */
16711686
int
@@ -2088,16 +2103,16 @@ gprofng_pread (ssize_t(real_pread) (int, void *, size_t, off_t),
20882103
return ret;
20892104
}
20902105

2091-
#define DCL_PREAD(dcl_f, real_f) \
2106+
#define DCL_PREAD(dcl_f) \
20922107
ssize_t dcl_f (int fildes, void *buf, size_t nbyte, off_t offset) \
20932108
{ \
2094-
if ((real_f) == NULL) \
2109+
if (__real_pread == NULL) \
20952110
init_io_intf (); \
2096-
return gprofng_pread (real_f, fildes, buf, nbyte, offset); \
2111+
return gprofng_pread (__real_pread, fildes, buf, nbyte, offset); \
20972112
}
20982113

20992114
DCL_FUNC_VER (DCL_PREAD, pread_2_2, pread@GLIBC_2.2)
2100-
DCL_PREAD (pread, CALL_REAL(pread))
2115+
DCL_PREAD (pread)
21012116

21022117
/*------------------------------------------------------------- pwrite */
21032118

@@ -2914,19 +2929,19 @@ gprofng_fgetpos (int(real_fgetpos) (FILE *stream, fpos_t *pos),
29142929
return ret;
29152930
}
29162931

2917-
#define DCL_FGETPOS(dcl_f, real_f) \
2932+
#define DCL_FGETPOS(dcl_f) \
29182933
int dcl_f (FILE *stream, fpos_t *pos) \
29192934
{ \
2920-
if ((real_f) == NULL) \
2935+
if (__real_fgetpos == NULL) \
29212936
init_io_intf (); \
2922-
return gprofng_fgetpos (real_f, stream, pos); \
2937+
return gprofng_fgetpos (__real_fgetpos, stream, pos); \
29232938
}
29242939

29252940
DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_17, fgetpos@GLIBC_2.17)
29262941
DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_2_5, fgetpos@GLIBC_2.2.5)
29272942
DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_2, fgetpos@GLIBC_2.2)
29282943
DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_0, fgetpos@GLIBC_2.0)
2929-
DCL_FGETPOS (fgetpos, CALL_REAL(fgetpos))
2944+
DCL_FGETPOS (fgetpos)
29302945

29312946
/*------------------------------------------------------------- fgetpos64 */
29322947
static int
@@ -2962,19 +2977,19 @@ gprofng_fgetpos64 (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos)
29622977
return ret;
29632978
}
29642979

2965-
#define DCL_FGETPOS64(dcl_f, real_f) \
2980+
#define DCL_FGETPOS64(dcl_f) \
29662981
int dcl_f (FILE *stream, fpos64_t *pos) \
29672982
{ \
2968-
if ((real_f) == NULL) \
2983+
if (__real_fgetpos64 == NULL) \
29692984
init_io_intf (); \
2970-
return gprofng_fgetpos64 (real_f, stream, pos); \
2985+
return gprofng_fgetpos64 (__real_fgetpos64, stream, pos); \
29712986
}
29722987

29732988
DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_17, fgetpos64@GLIBC_2.17)
29742989
DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_2_5, fgetpos64@GLIBC_2.2.5)
29752990
DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_2, fgetpos64@GLIBC_2.2)
29762991
DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_1, fgetpos64@GLIBC_2.1)
2977-
DCL_FGETPOS64 (fgetpos64, CALL_REAL(fgetpos64))
2992+
DCL_FGETPOS64 (fgetpos64)
29782993

29792994
/*------------------------------------------------------------- fsetpos */
29802995
static int
@@ -3011,19 +3026,19 @@ gprofng_fsetpos (int(real_fsetpos) (FILE *, const fpos_t *),
30113026
return ret;
30123027
}
30133028

3014-
#define DCL_FSETPOS(dcl_f, real_f) \
3029+
#define DCL_FSETPOS(dcl_f) \
30153030
int dcl_f (FILE *stream, const fpos_t *pos) \
30163031
{ \
3017-
if ((real_f) == NULL) \
3032+
if (__real_fsetpos == NULL) \
30183033
init_io_intf (); \
3019-
return gprofng_fsetpos (real_f, stream, pos); \
3034+
return gprofng_fsetpos (__real_fsetpos, stream, pos); \
30203035
}
30213036

30223037
DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_17, fsetpos@GLIBC_2.17)
30233038
DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_2_5, fsetpos@GLIBC_2.2.5)
30243039
DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_2, fsetpos@GLIBC_2.2)
30253040
DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_0, fsetpos@GLIBC_2.0)
3026-
DCL_FSETPOS (fsetpos, CALL_REAL(fsetpos))
3041+
DCL_FSETPOS (fsetpos)
30273042

30283043
/*------------------------------------------------------------- fsetpos64 */
30293044
static int
@@ -3060,19 +3075,19 @@ gprofng_fsetpos64 (int(real_fsetpos64) (FILE *, const fpos64_t *),
30603075
return ret;
30613076
}
30623077

3063-
#define DCL_FSETPOS64(dcl_f, real_f) \
3078+
#define DCL_FSETPOS64(dcl_f) \
30643079
int dcl_f (FILE *stream, const fpos64_t *pos) \
30653080
{ \
3066-
if ((real_f) == NULL) \
3081+
if (__real_fsetpos64 == NULL) \
30673082
init_io_intf (); \
3068-
return gprofng_fsetpos64 (real_f, stream, pos); \
3083+
return gprofng_fsetpos64 (__real_fsetpos64, stream, pos); \
30693084
}
30703085

30713086
DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_17, fsetpos64@GLIBC_2.17)
30723087
DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_2_5, fsetpos64@GLIBC_2.2.5)
30733088
DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_2, fsetpos64@GLIBC_2.2)
30743089
DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_1, fsetpos64@GLIBC_2.1)
3075-
DCL_FSETPOS64 (fsetpos64, CALL_REAL(fsetpos64))
3090+
DCL_FSETPOS64 (fsetpos64)
30763091

30773092
/*------------------------------------------------------------- fsync */
30783093
int

0 commit comments

Comments
 (0)