Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lld/ELF/Arch/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,8 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
// address may escape if referenced by a direct relocation. If relative
// vtables are used then if the vtable is in a shared object the offsets will
// be to the PLT entry. The condition is conservative.
bool hasBti = btiHeader &&
(sym.hasFlag(NEEDS_COPY) || sym.isInIplt || sym.thunkAccessed);
bool hasBti = btiHeader && (sym.hasFlag(NEEDS_COPY) || sym.isInIplt ||
sym.thunkAccessed || ctx.arg.forceBtiPlt);
if (hasBti) {
memcpy(buf, btiData, sizeof(btiData));
buf += sizeof(btiData);
Expand Down
1 change: 1 addition & 0 deletions lld/ELF/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ struct Config {
bool exportDynamic;
bool fixCortexA53Errata843419;
bool fixCortexA8;
bool forceBtiPlt = false;
bool formatBinary = false;
bool fortranCommon;
bool gcSections;
Expand Down
1 change: 1 addition & 0 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
ctx.arg.nmagic = args.hasFlag(OPT_nmagic, OPT_no_nmagic, false);
ctx.arg.noinhibitExec = args.hasArg(OPT_noinhibit_exec);
ctx.arg.nostdlib = args.hasArg(OPT_nostdlib);
ctx.arg.forceBtiPlt = args.hasArg(OPT_bti_plt);
ctx.arg.oFormatBinary = isOutputFormatBinary(ctx, args);
ctx.arg.omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);
ctx.arg.optRemarksFilename = args.getLastArgValue(OPT_opt_remarks_filename);
Expand Down
2 changes: 2 additions & 0 deletions lld/ELF/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ defm eh_frame_hdr: B<"eh-frame-hdr",

def emit_relocs: F<"emit-relocs">, HelpText<"Generate relocations in output">;

def bti_plt: FF<"force-bti-plt">, HelpText<"Force all PLT entries to have BTI">;

def enable_new_dtags: F<"enable-new-dtags">,
HelpText<"Enable new dynamic tags (default)">;

Expand Down
7 changes: 7 additions & 0 deletions lld/test/ELF/aarch64-feature-bti.s
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@
# REPORT-ERR: error: unknown -z bti-report= value: u{{$}}
# REPORT-EMPTY:

## Force all PLT entries to start with BTI with the force-bti-plt command line option.
# RUN: ld.lld %t.o %t2.o -z force-bti --force-bti-plt %t.so -o %tforcebtiplt.exe
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tforcebtiplt.exe | FileCheck --check-prefix=FORCE-BTI %s

# FORCE-BTI: 00000000002103a0 <func2@plt>:
# FORCE-BTI-NEXT: 2103a0: bti c

.section ".note.gnu.property", "a"
.long 4
.long 0x10
Expand Down
Loading