Skip to content

Commit

Permalink
Bug#29959277 With ASAN mtr fail due to: +ERROR: ld.so: object '/lib64…
Browse files Browse the repository at this point in the history
…/libtirpc.so' from LD_PRELOAD cannot be preloaded

Problem
=======
Running mtr with ASAN build on Gentoo tests fails since the path to
libtirpc is not /lib64/libtirpc.so which is the path mtr uses for
preloading the library.

Further more the libasan path in Gentoo may contain also underscores and
minus which mtr safe_process does not recognize.

Fails on Gentoo since /lib64/libtirpc.so do not exist
+ERROR: ld.so: object '/lib64/libtirpc.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

Fails on Gentoo since /usr/lib64/libtirpc.so is a GNU LD script
+ERROR: ld.so: object '/usr/lib64/libtirpc.so' from LD_PRELOAD cannot be preloaded (invalid ELF header): ignored.

Need to preload /lib64/libtirpc.so.3 on gentoo.

When compiling with GNU C++ libasan path also include minus and underscores:

$ less mysql-test/lib/My/SafeProcess/ldd_asan_test_result
        linux-vdso.so.1 (0x00007ffeba962000)
        libasan.so.4 => /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libasan.so.4 (0x00007f3c2e827000)

Tests that been affected in different ways are for example:

$ ./mtr group_replication.gr_clone_integration_clone_not_installed
[100%] group_replication.gr_clone_integration_clone_not_installed w3  [ fail ]
...
ERROR: ld.so: object '/usr/lib/gcc/x86' from LD_PRELOAD cannot be preloaded
(cannot open shared object file): ignored.
ERROR: ld.so: object '/lib64/libtirpc.so' from LD_PRELOAD cannot be preloaded
(cannot open shared object file): ignored.
mysqltest: At line 21: Query 'START GROUP_REPLICATION' failed.
ERROR 2013 (HY000): Lost connection to MySQL server during query
...
ASAN:DEADLYSIGNAL
=================================================================
==11970==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc
0x7f0e5cecfb8c bp 0x7f0e340f1650 sp 0x7f0e340f0dc8 T44)
==11970==The signal is caused by a READ memory access.
==11970==Hint: address points to the zero page.
    #0 0x7f0e5cecfb8b in xdr_uint32_t (/lib64/libc.so.6+0x13cb8b)
    #1 0x7f0e5fbe6d43
(/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libasan.so.4+0x87d43)
    #2 0x7f0e3c675e59 in xdr_node_no
plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp_xdr.c:88
    #3 0x7f0e3c67744d in xdr_pax_msg_1_6
plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp_xdr.c:852
...

$ ./mtr ndb.ndb_config
[100%] ndb.ndb_config                             [ fail ]
...
 --- /.../src/mysql-test/suite/ndb/r/ndb_config.result 2019-06-25
21:19:08.308997942 +0300
 +++ /.../bld/mysql-test/var/log/ndb_config.reject     2019-06-26
11:58:11.718512944 +0300
@@ -30,16 +30,22 @@
 == 16 == bug44689
 192.168.0.1 192.168.0.2 192.168.0.3 192.168.0.4 192.168.0.1 192.168.0.1
 == 17 == bug49400
+ERROR: ld.so: object '/usr/lib/gcc/x86' from LD_PRELOAD cannot be preloaded
(cannot open shared object file): ignored.
+ERROR: ld.so: object '/lib64/libtirpc.so' from LD_PRELOAD cannot be
preloaded (cannot open shared object file): ignored.
  ERROR    -- at line 25: TCP connection is a duplicate of the existing TCP
link from line 14
  ERROR    -- at line 25: Could not store section of configuration file.

$ ./mtr ndb.ndb_basic
[100%] ndb.ndb_basic                             [ pass ]  34706
ERROR: ld.so: object '/usr/lib/gcc/x86' from LD_PRELOAD cannot be preloaded
(cannot open shared object file): ignored.
ERROR: ld.so: object '/lib64/libtirpc.so' from LD_PRELOAD cannot be preloaded
(cannot open shared object file): ignored.

Solution
========
In safe_process use same trick for libtirpc as for libasan to determine
path to library for pre loading.

Also allow underscores and minus in paths.

In addition also add some memory leak suppressions for perl.

Change-Id: Ia02e354a20cf8b279eb2573f3f8c2c39776343dc
  • Loading branch information
zmur committed Jun 27, 2019
1 parent fffd6b7 commit e88706d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 4 additions & 1 deletion mysql-test/lib/My/SafeProcess/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ IF(HAVE_ASAN AND TIRPC_FOUND)

ADD_CUSTOM_COMMAND(
OUTPUT asan_test.c
COMMAND ${CMAKE_COMMAND} -E echo "int main() { return 0; }" > asan_test.c
COMMAND ${CMAKE_COMMAND} -E echo
"extern int xdr_void(); int main() { xdr_void(); return 0; }"
> asan_test.c
VERBATIM
)
SET_SOURCE_FILES_PROPERTIES(asan_test.c PROPERTIES GENERATED TRUE)

ADD_EXECUTABLE(asan_test asan_test.c)
TARGET_LINK_LIBRARIES(asan_test ${TIRPC_LIBRARIES})
ADD_CUSTOM_COMMAND(
OUTPUT ldd_asan_test_result
DEPENDS asan_test
Expand Down
15 changes: 12 additions & 3 deletions mysql-test/lib/My/SafeProcess/read_ldd_output.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
Expand All @@ -25,14 +25,23 @@ STRING(REPLACE "\n" ";" LDD_FILE_LINES ${LDD_FILE_CONTENTS})

SET(ASAN_LIBRARY_NAME)
FOREACH(LINE ${LDD_FILE_LINES})
STRING(REGEX MATCH "^[\t ]*(libasan.so.[0-9]) => ([/a-z0-9.]+)" XXX ${LINE})
STRING(REGEX MATCH "^[\t ]*(libasan.so.[0-9]) => ([/a-zA-Z0-9._-]+)" XXX ${LINE})
IF(CMAKE_MATCH_1)
# MESSAGE(STATUS "LINE ${LINE}")
# MESSAGE(STATUS "XXX ${XXX}")
# MESSAGE(STATUS "CMAKE_MATCH_1 ${CMAKE_MATCH_1}")
# MESSAGE(STATUS "CMAKE_MATCH_2 ${CMAKE_MATCH_2}")
SET(ASAN_LIBRARY_NAME ${CMAKE_MATCH_2})
ENDIF()
STRING(REGEX MATCH "^[\t ]*(libtirpc.so.[0-9]) => ([/a-zA-Z0-9._-]+)" XXX ${LINE})
IF(CMAKE_MATCH_1)
# MESSAGE(STATUS "LINE ${LINE}")
# MESSAGE(STATUS "XXX ${XXX}")
# MESSAGE(STATUS "CMAKE_MATCH_1 ${CMAKE_MATCH_1}")
# MESSAGE(STATUS "CMAKE_MATCH_2 ${CMAKE_MATCH_2}")
SET(TIRPC_LIBRARY_NAME ${CMAKE_MATCH_2})
ENDIF()
ENDFOREACH()
FILE(WRITE ${OUTFILE}
"const char *asan_library_name=\"${ASAN_LIBRARY_NAME}\";")
"const char *asan_library_name=\"${ASAN_LIBRARY_NAME}\";"
"const char *tirpc_library_name=\"${TIRPC_LIBRARY_NAME}\";")
17 changes: 13 additions & 4 deletions mysql-test/lib/My/SafeProcess/safe_process.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -267,12 +267,21 @@ int main(int argc, char *const argv[]) {
#if defined(HAVE_ASAN) && defined(HAVE_TIRPC)
#include "asan_library_name.h"
std::string ld_preload = "LD_PRELOAD=";
int lib_count = 0;
if (strlen(asan_library_name) > 0) {
ld_preload.append(asan_library_name);
ld_preload.append(":");
lib_count++;
}
if (strlen(tirpc_library_name) > 0) {
if (lib_count > 0) {
ld_preload.append(":");
}
ld_preload.append(tirpc_library_name);
lib_count++;
}
if (lib_count > 0) {
putenv(strdup(ld_preload.c_str()));
}
ld_preload.append("/lib64/libtirpc.so");
putenv(strdup(ld_preload.c_str()));
#endif
if (execvp(child_argv[0], child_argv) < 0) die("Failed to exec child");
}
Expand Down
6 changes: 5 additions & 1 deletion mysql-test/lsan.supp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
Expand All @@ -24,3 +24,7 @@
leak:Perl_safesyscalloc
leak:Perl_safesysmalloc
leak:Perl_safesysrealloc
leak:Perl_savesharedpv
leak:Perl_Slab_Alloc
leak:Perl_newUNOP_AUX
leak:/usr/bin/perl

0 comments on commit e88706d

Please sign in to comment.