Skip to content

Commit 402acd2

Browse files
committed
Revert "[analyzer] Use absolute path to logger.so in LD_PRELOAD"
This reverts commit db924b0. ld_logger.so binary version (32 or 64 bits) must depend on the excuted builder binary version, not on the host machine platform version.
1 parent 9693dbb commit 402acd2

File tree

6 files changed

+31
-49
lines changed

6 files changed

+31
-49
lines changed

analyzer/codechecker_analyzer/analyzer_context.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
from argparse import ArgumentTypeError
1515

1616
import os
17-
import platform
1817
import sys
1918

20-
from pathlib import Path
21-
2219
from codechecker_analyzer.arg import analyzer_binary
2320
from codechecker_common import logger
2421
from codechecker_common.checker_labels import CheckerLabels
@@ -67,18 +64,12 @@ def __init__(self):
6764
self.__analyzers = {}
6865
self.__analyzer_env = None
6966

70-
machine = platform.uname().machine
71-
7267
self.logger_lib_dir_path = os.path.join(
73-
self._data_files_dir_path, 'ld_logger', 'lib', machine)
68+
self._data_files_dir_path, 'ld_logger', 'lib')
7469

7570
if not os.path.exists(self.logger_lib_dir_path):
7671
self.logger_lib_dir_path = os.path.join(
77-
self._lib_dir_path,
78-
'codechecker_analyzer',
79-
'ld_logger',
80-
'lib',
81-
machine)
72+
self._lib_dir_path, 'codechecker_analyzer', 'ld_logger', 'lib')
8273

8374
self.logger_bin = None
8475
self.logger_file = None
@@ -281,12 +272,8 @@ def path_logger_bin(self):
281272
return os.path.join(self._bin_dir_path, 'ld_logger')
282273

283274
@property
284-
def logger_lib_path(self):
285-
"""
286-
Returns the absolute path to the logger library.
287-
"""
288-
return str(Path(self.logger_lib_dir_path,
289-
self.logger_lib_name).absolute())
275+
def path_logger_lib(self):
276+
return self.logger_lib_dir_path
290277

291278
@property
292279
def logger_lib_name(self):

analyzer/codechecker_analyzer/env.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ def get_log_env(logfile, original_env):
2727

2828
new_env[context.env_var_cc_logger_bin] = context.path_logger_bin
2929

30-
new_env['LD_PRELOAD'] = context.logger_lib_path
30+
if 'LD_PRELOAD' in new_env:
31+
new_env['LD_PRELOAD'] = new_env['LD_PRELOAD'] + " " +context.logger_lib_name
32+
else:
33+
new_env['LD_PRELOAD'] = context.logger_lib_name
34+
35+
try:
36+
original_ld_library_path = new_env['LD_LIBRARY_PATH']
37+
new_env['LD_LIBRARY_PATH'] = context.path_logger_lib + ':' + \
38+
original_ld_library_path
39+
except KeyError:
40+
new_env['LD_LIBRARY_PATH'] = context.path_logger_lib
3141

3242
# Set ld logger logfile.
3343
new_env[context.env_var_cc_logger_file] = logfile

analyzer/tests/unit/test_log_parser.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111

1212
import json
1313
import os
14-
import platform
1514
import shutil
1615
import tempfile
1716
import unittest
1817

1918
from codechecker_analyzer.buildlog import log_parser
20-
from codechecker_analyzer.env import get_log_env
2119
from codechecker_common.skiplist_handler import SkipListHandler, \
2220
SkipListHandlers
2321
from codechecker_common.util import load_json
@@ -664,24 +662,3 @@ def test_symlink(self):
664662

665663
self.assertEqual(len(build_actions), 3)
666664
self.assertEqual(build_action.source, file_c_symdir)
667-
668-
def test_get_log_env(self):
669-
"""
670-
Test if get_log_env returns the correct environment
671-
with LD_PRELOAD set to pointing to the correct directory
672-
of the ldlogger.so lib.
673-
"""
674-
log_file = os.path.join(self.tmp_dir, "compile_commands.json")
675-
original_env = os.environ.copy()
676-
# If this asset fails, make sure that you don't have LD_PRELOAD set
677-
# in your environment.
678-
self.assertNotIn("LD_PRELOAD", original_env)
679-
env = get_log_env(log_file, original_env)
680-
681-
# The new environment should contain the LD_PRELOAD variable.
682-
self.assertIn("LD_PRELOAD", env)
683-
684-
# Make sure that the test running machine architecture is in the
685-
# LD_PRELOAD path.
686-
machine = platform.uname().machine
687-
self.assertTrue(env["LD_PRELOAD"].endswith(machine + "/ldlogger.so"))

analyzer/tools/build-logger/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ make all test
1414

1515
Set the following environment variables:
1616
~~~~~~~
17-
export LD_PRELOAD=`pwd`/build/lib/`uname -m`/ldlogger.so
18-
export CC_LOGGER_GCC_LIKE="gcc:g++:clang:clang++:/cc:c++"
17+
export LD_PRELOAD=ldlogger.so
18+
export LD_LIBRARY_PATH=`pwd`/build/lib:$LD_LIBRARY_PATH
19+
export CC_LOGGER_GCC_LIKE="gcc:g++:clang:clang++:cc:c++"
1920
# The output compilation JSON file.
2021
export CC_LOGGER_FILE=`pwd`/compilation.json
2122
# Log linker build actions to the JSON file. Optional. Default: false

analyzer/tools/build-logger/tests/unit/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,11 @@ def read_actual_json(self) -> str:
106106
return fd.read()
107107

108108
def get_envvars(self) -> Mapping[str, str]:
109-
machine = platform.uname().machine
110109
return {
111110
"PATH": os.getenv("PATH"),
112-
"LD_PRELOAD": os.path.join(LOGGER_DIR,
113-
"lib",
114-
machine,
115-
"ldlogger.so"),
116-
"CC_LOGGER_GCC_LIKE": "gcc:g++:clang:clang++:/cc:c++",
111+
"LD_PRELOAD": "ldlogger.so",
112+
"LD_LIBRARY_PATH": os.path.join(LOGGER_DIR, "lib"),
113+
"CC_LOGGER_GCC_LIKE": "gcc:g++:clang:clang++:cc:c++",
117114
"CC_LOGGER_FILE": self.logger_file,
118115
"CC_LOGGER_DEBUG_FILE": self.logger_debug_file,
119116
}

docs/analyzer/user_guide.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,16 @@ object files as input) should be captured. For further details see
756756
[this documentation](/analyzer/tools/build-logger/README.md).
757757

758758

759+
If your build tool overrides `LD_LIBRARY_PATH` during the build process, then
760+
`ldlogger.so` will not be found. The best solution is to making sure
761+
that the LD_LIBRARY_PATH is not overridden, only extended.
762+
If this is not possible, you can work around the situation by
763+
specifying the absolute path of the `ldlogger.so` in the `LD_PRELOAD`:
764+
765+
```sh
766+
LD_PRELOAD=<CODECHECKER_DIR>/ld_logger/lib/x86_64/ldlogger.so CodeChecker log -o compile_commands.json -b "make -j2"
767+
```
768+
759769
#### Change user inside the build command
760770
If we change user inside the build command of the CodeChecker log command
761771
before the actual compiler invocation, the compilation database will be empty:

0 commit comments

Comments
 (0)