Skip to content

Commit d2eefad

Browse files
committed
[LLD] Add flag to force PLT entries to have a BTI
1 parent a51c1f8 commit d2eefad

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,8 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
11861186
// address may escape if referenced by a direct relocation. If relative
11871187
// vtables are used then if the vtable is in a shared object the offsets will
11881188
// be to the PLT entry. The condition is conservative.
1189-
bool hasBti = btiHeader &&
1190-
(sym.hasFlag(NEEDS_COPY) || sym.isInIplt || sym.thunkAccessed);
1189+
bool hasBti = btiHeader && (sym.hasFlag(NEEDS_COPY) || sym.isInIplt ||
1190+
sym.thunkAccessed || ctx.arg.forceBtiPlt);
11911191
if (hasBti) {
11921192
memcpy(buf, btiData, sizeof(btiData));
11931193
buf += sizeof(btiData);

lld/ELF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ struct Config {
330330
bool exportDynamic;
331331
bool fixCortexA53Errata843419;
332332
bool fixCortexA8;
333+
bool forceBtiPlt = false;
333334
bool formatBinary = false;
334335
bool fortranCommon;
335336
bool gcSections;

lld/ELF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14861486
ctx.arg.nmagic = args.hasFlag(OPT_nmagic, OPT_no_nmagic, false);
14871487
ctx.arg.noinhibitExec = args.hasArg(OPT_noinhibit_exec);
14881488
ctx.arg.nostdlib = args.hasArg(OPT_nostdlib);
1489+
ctx.arg.forceBtiPlt = args.hasArg(OPT_bti_plt);
14891490
ctx.arg.oFormatBinary = isOutputFormatBinary(ctx, args);
14901491
ctx.arg.omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);
14911492
ctx.arg.optRemarksFilename = args.getLastArgValue(OPT_opt_remarks_filename);

lld/ELF/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ defm eh_frame_hdr: B<"eh-frame-hdr",
212212

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

215+
def bti_plt: FF<"force-bti-plt">, HelpText<"Force all PLT entries to have BTI">;
216+
215217
def enable_new_dtags: F<"enable-new-dtags">,
216218
HelpText<"Enable new dynamic tags (default)">;
217219

lld/test/ELF/aarch64-feature-bti.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@
262262
# REPORT-ERR: error: unknown -z bti-report= value: u{{$}}
263263
# REPORT-EMPTY:
264264

265+
## Force all PLT entries to start with BTI with the force-bti-plt command line option.
266+
# RUN: ld.lld %t.o %t2.o -z force-bti --force-bti-plt %t.so -o %tforcebtiplt.exe
267+
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %tforcebtiplt.exe | FileCheck --check-prefix=FORCE-BTI %s
268+
269+
# FORCE-BTI: 00000000002103a0 <func2@plt>:
270+
# FORCE-BTI-NEXT: 2103a0: bti c
271+
265272
.section ".note.gnu.property", "a"
266273
.long 4
267274
.long 0x10

0 commit comments

Comments
 (0)