Skip to content

Commit

Permalink
[wasm] Add function-pointer-alignment function
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien committed Dec 30, 2024
1 parent 58d4069 commit d8df549
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions lld/wasm/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct Config {
// for shared libraries (since they always added to a dynamic offset at
// runtime).
uint64_t tableBase;
uint64_t functionPointerAlignment;
uint64_t zStackSize;
unsigned ltoPartitions;
unsigned ltoo;
Expand Down
1 change: 1 addition & 0 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ static void readConfigs(opt::InputArgList &args) {
LLVM_DEBUG(errorHandler().verbose = true);

config->tableBase = args::getInteger(args, OPT_table_base, 0);
config->functionPointerAlignment = args::getInteger(args, OPT_function_pointer_alignment, 0);
config->globalBase = args::getInteger(args, OPT_global_base, 0);
config->initialHeap = args::getInteger(args, OPT_initial_heap, 0);
config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
Expand Down
3 changes: 3 additions & 0 deletions lld/wasm/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def stack_first: FF<"stack-first">,
def table_base: JJ<"table-base=">,
HelpText<"Table offset at which to place address taken functions (Defaults to 1)">;

def function_pointer_alignment: JJ<"function-pointer-alignment=">,
HelpText<"Align function pointers at a given value (Defaults to 1)">;

defm whole_archive: B<"whole-archive",
"Force load of all members in a static library",
"Do not force load of all members in a static library (default)">;
Expand Down
13 changes: 2 additions & 11 deletions lld/wasm/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,20 +567,11 @@ void ElemSection::addEntry(FunctionSymbol *sym) {
if (sym->hasTableIndex() || sym->isStub)
return;

uint32_t padding = 0;
uint64_t alignment = 1;

if (indirectFunctions.size() == 0 && padding > 0) {
for (uint32_t i=0; i<padding; i++) {
indirectFunctions.push_back(nullptr);
}
}

sym->setTableIndex(config->tableBase + indirectFunctions.size());
indirectFunctions.emplace_back(sym);

if (alignment > 1) {
for (uint32_t i=0; i<alignment-1; i++) {
if (config->functionPointerAlignment > 1) {
for (uint32_t i=0; i<config->functionPointerAlignment-1; i++) {
indirectFunctions.push_back(nullptr);
}
}
Expand Down

0 comments on commit d8df549

Please sign in to comment.