Skip to content

Commit cb250f6

Browse files
author
Tom Yang
committed
remove defer_module_preload bool flag, remove preload from
Target::GetOrCreateModule Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 51d6bc6 commit cb250f6

File tree

10 files changed

+57
-79
lines changed

10 files changed

+57
-79
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,10 @@ class ModuleList {
512512
void Swap(ModuleList &other);
513513

514514
/// For each module in this ModuleList, preload its symbols.
515-
void PreloadSymbols() const;
515+
///
516+
/// \param[in] parallelize
517+
/// If true, all modules will be preloaded in parallel.
518+
void PreloadSymbols(bool parallelize) const;
516519

517520
protected:
518521
// Class typedefs.

lldb/include/lldb/Target/DynamicLoader.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,10 @@ class DynamicLoader : public PluginInterface {
208208
/// Note that this calls Target::GetOrCreateModule with notify being false,
209209
/// so it is necessary to call Target::ModulesDidLoad afterwards.
210210
///
211-
/// \param[in] defer_module_preload
212-
/// If the module needs to be loaded, prevent the module from being
213-
/// preloaded even if the user sets the preload symbols option. This is
214-
/// used as a performance optimization should the caller preload the
215-
/// modules in parallel after calling this function.
216211
virtual lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,
217212
lldb::addr_t link_map_addr,
218213
lldb::addr_t base_addr,
219-
bool base_addr_is_offset,
220-
bool defer_module_preload = false);
214+
bool base_addr_is_offset);
221215

222216
/// Find/load a binary into lldb given a UUID and the address where it is
223217
/// loaded in memory, or a slide to be applied to the file address.
@@ -360,12 +354,7 @@ class DynamicLoader : public PluginInterface {
360354
// Utility methods for derived classes
361355

362356
/// Find a module in the target that matches the given file.
363-
///
364-
/// \param[in] defer_module_preload
365-
/// If the module needs to be loaded, prevent the module from being
366-
/// preloaded even if the user sets the preload symbols option.
367-
lldb::ModuleSP FindModuleViaTarget(const FileSpec &file,
368-
bool defer_module_preload = false);
357+
lldb::ModuleSP FindModuleViaTarget(const FileSpec &file);
369358

370359
/// Checks to see if the target module has changed, updates the target
371360
/// accordingly and returns the target executable module.

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,20 +649,12 @@ class Target : public std::enable_shared_from_this<Target>,
649649
/// will handle / summarize the failures in a custom way and
650650
/// don't use these messages.
651651
///
652-
/// \param[in] defer_preload
653-
/// If true, the module will not be preloaded even if
654-
/// Target::GetPreloadSymbols() is true. This is useful when the caller
655-
/// wishes to preload loaded modules in parallel after calling this
656-
/// function for better performance. This is because it's currently not
657-
/// thread-safe to do so during the execution of this function.
658-
///
659652
/// \return
660653
/// An empty ModuleSP will be returned if no matching file
661654
/// was found. If error_ptr was non-nullptr, an error message
662655
/// will likely be provided.
663656
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify,
664-
Status *error_ptr = nullptr,
665-
bool defer_preload = false);
657+
Status *error_ptr = nullptr);
666658

667659
// Settings accessors
668660

lldb/source/Core/DynamicLoader.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP module) const {
154154
return sections;
155155
}
156156

157-
ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file,
158-
bool defer_module_preload) {
157+
ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
159158
Target &target = m_process->GetTarget();
160159
ModuleSpec module_spec(file, target.GetArchitecture());
161160
if (UUID uuid = m_process->FindModuleUUID(file.GetPath())) {
@@ -167,8 +166,7 @@ ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file,
167166
return module_sp;
168167

169168
if (ModuleSP module_sp = target.GetOrCreateModule(
170-
module_spec, false /* notify */, nullptr /* error_ptr */,
171-
defer_module_preload))
169+
module_spec, false /* notify */, nullptr /* error_ptr */))
172170
return module_sp;
173171

174172
return nullptr;
@@ -177,9 +175,8 @@ ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file,
177175
ModuleSP DynamicLoader::LoadModuleAtAddress(const FileSpec &file,
178176
addr_t link_map_addr,
179177
addr_t base_addr,
180-
bool base_addr_is_offset,
181-
bool defer_module_preload) {
182-
if (ModuleSP module_sp = FindModuleViaTarget(file, defer_module_preload)) {
178+
bool base_addr_is_offset) {
179+
if (ModuleSP module_sp = FindModuleViaTarget(file)) {
183180
UpdateLoadedSections(module_sp, link_map_addr, base_addr,
184181
base_addr_is_offset);
185182
return module_sp;

lldb/source/Core/ModuleList.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,16 @@ void ModuleList::Swap(ModuleList &other) {
13601360
m_modules.swap(other.m_modules);
13611361
}
13621362

1363-
void ModuleList::PreloadSymbols() const {
1363+
void ModuleList::PreloadSymbols(bool parallelize) const {
13641364
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
1365+
1366+
if (!parallelize) {
1367+
for (const ModuleSP &module_sp : m_modules)
1368+
module_sp->PreloadSymbols();
1369+
return;
1370+
}
1371+
1372+
// parallelize
13651373
llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
13661374
for (const ModuleSP &module_sp : m_modules)
13671375
task_group.async([module_sp] {

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
453453
// exists for the duration of this call in `m_rendezvous`.
454454
auto load_module_fn =
455455
[this, &loaded_modules, &new_modules,
456-
&interpreter_module_mutex](const DYLDRendezvous::SOEntry &so_entry,
457-
bool defer_module_preload) {
456+
&interpreter_module_mutex](const DYLDRendezvous::SOEntry &so_entry) {
458457
// Don't load a duplicate copy of ld.so if we have already loaded it
459458
// earlier in LoadInterpreterModule. If we instead loaded then
460459
// unloaded it later, the section information for ld.so would be
@@ -471,7 +470,7 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
471470

472471
ModuleSP module_sp = LoadModuleAtAddress(
473472
so_entry.file_spec, so_entry.link_addr, so_entry.base_addr,
474-
true /* base_addr_is_offset */, defer_module_preload);
473+
true /* base_addr_is_offset */);
475474
if (!module_sp.get())
476475
return;
477476

@@ -505,16 +504,17 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
505504
if (m_process->GetTarget().GetParallelModuleLoad()) {
506505
llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
507506
for (; I != E; ++I)
508-
task_group.async(load_module_fn, *I, true /* defer_module_preload */);
507+
task_group.async(load_module_fn, *I);
509508
task_group.wait();
510-
511-
if (m_process->GetTarget().GetPreloadSymbols())
512-
new_modules.PreloadSymbols();
513509
} else {
514510
for (; I != E; ++I)
515-
load_module_fn(*I, false /* defer_module_preload */);
511+
load_module_fn(*I);
516512
}
517513

514+
if (m_process->GetTarget().GetPreloadSymbols())
515+
new_modules.PreloadSymbols(
516+
m_process->GetTarget().GetParallelModuleLoad());
517+
518518
m_process->GetTarget().ModulesDidLoad(new_modules);
519519
}
520520

@@ -649,12 +649,12 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
649649
return nullptr;
650650
}
651651

652-
ModuleSP DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(
653-
const FileSpec &file, addr_t link_map_addr, addr_t base_addr,
654-
bool base_addr_is_offset, bool defer_module_preload) {
652+
ModuleSP DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(const FileSpec &file,
653+
addr_t link_map_addr,
654+
addr_t base_addr,
655+
bool base_addr_is_offset) {
655656
if (ModuleSP module_sp = DynamicLoader::LoadModuleAtAddress(
656-
file, link_map_addr, base_addr, base_addr_is_offset,
657-
defer_module_preload))
657+
file, link_map_addr, base_addr, base_addr_is_offset))
658658
return module_sp;
659659

660660
// This works around an dynamic linker "bug" on android <= 23, where the
@@ -673,7 +673,7 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(
673673
!(memory_info.GetName().IsEmpty())) {
674674
if (ModuleSP module_sp = DynamicLoader::LoadModuleAtAddress(
675675
FileSpec(memory_info.GetName().GetStringRef()), link_map_addr,
676-
base_addr, base_addr_is_offset, defer_module_preload))
676+
base_addr, base_addr_is_offset))
677677
return module_sp;
678678
}
679679
}
@@ -709,11 +709,9 @@ void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {
709709
module_names, m_process->GetTarget().GetArchitecture().GetTriple());
710710

711711
auto load_module_fn = [this, &module_list,
712-
&log](const DYLDRendezvous::SOEntry &so_entry,
713-
bool defer_module_preload) {
714-
ModuleSP module_sp =
715-
LoadModuleAtAddress(so_entry.file_spec, so_entry.link_addr,
716-
so_entry.base_addr, true, defer_module_preload);
712+
&log](const DYLDRendezvous::SOEntry &so_entry) {
713+
ModuleSP module_sp = LoadModuleAtAddress(
714+
so_entry.file_spec, so_entry.link_addr, so_entry.base_addr, true);
717715
if (module_sp.get()) {
718716
LLDB_LOG(log, "LoadAllCurrentModules loading module: {0}",
719717
so_entry.file_spec.GetFilename());
@@ -730,16 +728,14 @@ void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {
730728
if (m_process->GetTarget().GetParallelModuleLoad()) {
731729
llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
732730
for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
733-
task_group.async(load_module_fn, *I, true /* defer_module_preload */);
731+
task_group.async(load_module_fn, *I);
734732
task_group.wait();
733+
} else
734+
for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
735+
load_module_fn(*I);
735736

736-
if (m_process->GetTarget().GetPreloadSymbols())
737-
module_list.PreloadSymbols();
738-
} else {
739-
for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) {
740-
load_module_fn(*I, false /* defer_module_preload */);
741-
}
742-
}
737+
if (m_process->GetTarget().GetPreloadSymbols())
738+
module_list.PreloadSymbols(m_process->GetTarget().GetParallelModuleLoad());
743739

744740
m_process->GetTarget().ModulesDidLoad(module_list);
745741
m_initial_modules_added = true;

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
5555
// PluginInterface protocol
5656
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
5757

58-
lldb::ModuleSP
59-
LoadModuleAtAddress(const lldb_private::FileSpec &file,
60-
lldb::addr_t link_map_addr, lldb::addr_t base_addr,
61-
bool base_addr_is_offset,
62-
bool defer_module_preload = false) override;
58+
lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,
59+
lldb::addr_t link_map_addr,
60+
lldb::addr_t base_addr,
61+
bool base_addr_is_offset) override;
6362

6463
void CalculateDynamicSaveCoreRanges(
6564
lldb_private::Process &process,

lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ ThreadPlanSP DynamicLoaderWasmDYLD::GetStepThroughTrampolinePlan(Thread &thread,
6767

6868
lldb::ModuleSP DynamicLoaderWasmDYLD::LoadModuleAtAddress(
6969
const lldb_private::FileSpec &file, lldb::addr_t link_map_addr,
70-
lldb::addr_t base_addr, bool base_addr_is_offset,
71-
bool defer_module_preload) {
70+
lldb::addr_t base_addr, bool base_addr_is_offset) {
7271
if (ModuleSP module_sp = DynamicLoader::LoadModuleAtAddress(
73-
file, link_map_addr, base_addr, base_addr_is_offset,
74-
defer_module_preload))
72+
file, link_map_addr, base_addr, base_addr_is_offset)) {
73+
if (m_process->GetTarget().GetPreloadSymbols())
74+
module_sp->PreloadSymbols();
7575
return module_sp;
76+
}
7677

7778
if (ModuleSP module_sp = m_process->ReadModuleFromMemory(file, base_addr)) {
7879
UpdateLoadedSections(module_sp, link_map_addr, base_addr, false);

lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ class DynamicLoaderWasmDYLD : public DynamicLoader {
3333
Status CanLoadImage() override { return Status(); }
3434
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
3535
bool stop) override;
36-
lldb::ModuleSP
37-
LoadModuleAtAddress(const lldb_private::FileSpec &file,
38-
lldb::addr_t link_map_addr, lldb::addr_t base_addr,
39-
bool base_addr_is_offset,
40-
bool defer_module_preload = false) override;
36+
lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,
37+
lldb::addr_t link_map_addr,
38+
lldb::addr_t base_addr,
39+
bool base_addr_is_offset) override;
4140

4241
/// \}
4342

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,8 +2342,7 @@ bool Target::ReadPointerFromMemory(const Address &addr, Status &error,
23422342
}
23432343

23442344
ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
2345-
bool notify, Status *error_ptr,
2346-
bool defer_preload) {
2345+
bool notify, Status *error_ptr) {
23472346
ModuleSP module_sp;
23482347

23492348
Status error;
@@ -2509,11 +2508,6 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
25092508
if (symbol_file_spec)
25102509
module_sp->SetSymbolFileFileSpec(symbol_file_spec);
25112510

2512-
// Preload symbols outside of any lock, so hopefully we can do this for
2513-
// each library in parallel.
2514-
if (GetPreloadSymbols() && !defer_preload)
2515-
module_sp->PreloadSymbols();
2516-
25172511
llvm::SmallVector<ModuleSP, 1> replaced_modules;
25182512
for (ModuleSP &old_module_sp : old_modules) {
25192513
if (m_images.GetIndexForModule(old_module_sp.get()) !=

0 commit comments

Comments
 (0)