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