Skip to content

Commit

Permalink
[ELF] Support LDPT_GET_API_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Jun 30, 2022
1 parent 5688115 commit 9ad49d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
19 changes: 17 additions & 2 deletions elf/lto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static std::vector<PluginSymbol> plugin_symbols;
static ClaimFileHandler *claim_file_hook;
static AllSymbolsReadHandler *all_symbols_read_hook;
static CleanupHandler *cleanup_hook;
static bool is_gcc_linker_api_v1 = false;

// Event handlers

Expand Down Expand Up @@ -398,6 +399,19 @@ get_wrap_symbols(uint64_t *num_symbols, const char ***wrap_symbols) {
return LDPS_OK;
}

static PluginLinkerAPIVersion
get_api_version(const char *plugin_identifier,
unsigned plugin_version,
PluginLinkerAPIVersion minimal_api_supported,
PluginLinkerAPIVersion maximal_api_supported,
const char **linker_identifier,
unsigned *linker_version) {
assert(maximal_api_supported >= LAPI_V1);
*linker_identifier = "mold";
is_gcc_linker_api_v1 = true;
return LAPI_V1;
}

template <typename E>
static void load_plugin(Context<E> &ctx) {
assert(phase == 0);
Expand Down Expand Up @@ -458,6 +472,7 @@ static void load_plugin(Context<E> &ctx) {
tv.emplace_back(LDPT_GET_INPUT_SECTION_SIZE, get_input_section_size);
tv.emplace_back(LDPT_REGISTER_NEW_INPUT_HOOK, register_new_input_hook<E>);
tv.emplace_back(LDPT_GET_WRAP_SYMBOLS, get_wrap_symbols);
tv.emplace_back(LDPT_GET_API_VERSION, get_api_version);
tv.emplace_back(LDPT_NULL, 0);

onload(tv.data());
Expand Down Expand Up @@ -524,10 +539,10 @@ static bool is_llvm(Context<E> &ctx) {
}

// Returns true if a given linker plugin supports the get_symbols_v3 API.
// Currently, we simply assume that LLVM supports it and GCC does not.
// Any version of LLVM and GCC 12 or newer support it.
template <typename E>
static bool suppots_v3_api(Context<E> &ctx) {
return is_llvm(ctx);
return is_gcc_linker_api_v1 || is_llvm(ctx);
}

template <typename E>
Expand Down
6 changes: 6 additions & 0 deletions elf/lto.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum PluginTag {
LDPT_REGISTER_NEW_INPUT_HOOK,
LDPT_GET_WRAP_SYMBOLS,
LDPT_ADD_SYMBOLS_V2,
LDPT_GET_API_VERSION,
};

enum PluginApiVersion {
Expand Down Expand Up @@ -141,6 +142,11 @@ enum PluginLevel {
LDPL_FATAL,
};

enum PluginLinkerAPIVersion {
LAPI_UNSPECIFIED = 0,
LAPI_V1 = 1,
};

typedef PluginStatus OnloadFn(PluginTagValue *tv);
typedef PluginStatus ClaimFileHandler(const PluginInputFile *, int *);
typedef PluginStatus AllSymbolsReadHandler();
Expand Down
2 changes: 0 additions & 2 deletions test/elf/lto-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ cd "$(dirname "$0")"/../..
t=out/test/elf/$testname
mkdir -p $t

[ "$CC" = cc ] || { echo skipped; exit; }

cat <<EOF | $CC -o $t/a.o -c -flto -xc -
#include <stdio.h>
void hello() {
Expand Down

0 comments on commit 9ad49d1

Please sign in to comment.