Coverage Report

Created: 2026-07-07 12:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/dynamic_util.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/apache/impala/blob/branch-2.9.0/be/src/util/dynamic-util.cc
19
// and modified by Doris
20
21
#include "util/dynamic_util.h"
22
23
#include <dlfcn.h>
24
25
#include "common/phdr_cache.h"
26
#if defined(__ELF__) && !defined(__FreeBSD__)
27
#include "common/symbol_index.h"
28
#endif
29
30
namespace doris {
31
32
0
Status dynamic_lookup(void* handle, const char* symbol, void** fn_ptr) {
33
0
    *(void**)(fn_ptr) = dlsym(handle, symbol);
34
0
    char* error = dlerror();
35
36
0
    if (error != nullptr) {
37
0
        return Status::InternalError("Unable to find {}\ndlerror: {}", symbol, error);
38
0
    }
39
40
0
    return Status::OK();
41
0
}
42
43
1
Status dynamic_open(const char* library, void** handle) {
44
1
    int flags = RTLD_NOW;
45
46
1
    *handle = dlopen(library, flags);
47
48
1
    if (*handle == nullptr) {
49
0
        return Status::InternalError("Unable to load {}\ndlerror: {}", library, dlerror());
50
0
    }
51
52
    // Doris-controlled dynamic loads should be visible to diagnostic stack snapshots without
53
    // forcing the next /api/stack_trace request to rebuild loader-derived state on demand.
54
1
    updatePHDRCache();
55
1
#if defined(__ELF__) && !defined(__FreeBSD__)
56
1
    SymbolIndex::reload();
57
1
#endif
58
1
    return Status::OK();
59
1
}
60
61
1
void dynamic_close(void* handle) {
62
// There is an issue of LSAN can't deal well with dlclose(), so we disable LSAN here, more details:
63
// https://github.com/google/sanitizers/issues/89
64
#if !defined(ADDRESS_SANITIZER) && !defined(LEAK_SANITIZER)
65
    dlclose(handle);
66
    // Refresh after dlclose so later symbolization does not keep stale Doris-controlled library
67
    // entries. SymbolIndex::reload() serializes concurrent rebuilds internally.
68
    updatePHDRCache();
69
#if defined(__ELF__) && !defined(__FreeBSD__)
70
    SymbolIndex::reload();
71
#endif
72
#endif
73
1
}
74
75
} // namespace doris