1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CRAZY_LINKER_LIBRARY_LIST_H
6 #define CRAZY_LINKER_LIBRARY_LIST_H
10 #include "crazy_linker_error.h"
11 #include "crazy_linker_search_path_list.h"
12 #include "elf_traits.h"
14 // This header contains definitions related to the global list of
15 // library views maintained by the crazy linker. Each library view
16 // points to either a crazy library, or a system one.
23 // The list of all shared libraries loaded by the crazy linker.
24 // IMPORTANT: This class is not thread-safe!
30 // Find a library in the list by its base name.
31 // |base_name| must not contain a directory separator.
32 LibraryView* FindLibraryByName(const char* base_name);
34 // Lookup for a given |symbol_name|, starting from |from_lib|
35 // then through its dependencies in breadth-first search order.
36 // On failure, returns NULL.
37 void* FindSymbolFrom(const char* symbol_name, LibraryView* from_lib);
39 // Return the address of a visible given symbol. Used to implement
40 // the dlsym() wrapper. Returns NULL on failure.
41 void* FindAddressForSymbol(const char* symbol_name);
43 // Find a SharedLibrary that contains a given address, or NULL if none
44 // could be found. This simply scans all libraries.
45 LibraryView* FindLibraryForAddress(void* address);
48 // Find the base address of the .ARM.exidx section corresponding
49 // to the address |pc|, as well as the number of 8-byte entries in
50 // the table into |*count|. Used to implement the wrapper for
51 // dl_unwind_find_exidx().
52 _Unwind_Ptr FindArmExIdx(void* pc, int* count);
54 typedef int (*PhdrIterationCallback)(dl_phdr_info* info,
58 // Loop over all loaded libraries and call the |cb| callback
59 // on each iteration. If the function returns 0, stop immediately
60 // and return its value. Used to implement the wrapper for
62 int IteratePhdr(PhdrIterationCallback callback, void* data);
65 // Try to load a library, possibly at a fixed address.
66 // On failure, returns NULL and sets the |error| message.
67 LibraryView* LoadLibrary(const char* path,
69 uintptr_t load_address,
71 SearchPathList* search_path_list,
74 // Try to load a library from its location in the zip file.
75 // On failure, returns NULL and sets the |error| message.
76 LibraryView* LoadLibraryInZipFile(const char* zip_file_path,
79 uintptr_t load_address,
80 SearchPathList* search_path_list,
83 // Unload a given shared library. This really decrements the library's
84 // internal reference count. When it reaches zero, the library's
85 // destructors are run, its dependencies are unloaded, then the
86 // library is removed from memory.
87 void UnloadLibrary(LibraryView* lib);
89 // Used internally by the wrappers only.
90 void AddLibrary(LibraryView* lib);
93 LibraryList(const LibraryList&);
94 LibraryList& operator=(const LibraryList&);
98 // The list of all known libraries.
99 Vector<LibraryView*> known_libraries_;
101 LibraryView* FindKnownLibrary(const char* name);
103 // The list of all libraries loaded by the crazy linker.
104 // This does _not_ include system libraries present in known_libraries_.
105 SharedLibrary* head_;
109 char error_buffer_[512];
114 #endif // CRAZY_LINKER_LIBRARY_LIST_H