Skip to content

Commit 4e53911

Browse files
[BFD, AArch64, x86] Improve warning for --force-bti
The AArch64 linker option to turn on BTI (--force-bti) warns in case there are input objects which have a missing GNU NOTE section for BTI. This patch is trying to improve the warnings that come out. In order to do so, I propose adding a new argument to elf_merge_gnu_properties and the backend function merge_gnu_properties. This new argument makes sure that we now pass both the objects along with the properties to which they belong to. The x86 backend function has also been updated to match this change. *** bfd/ChangeLog *** 2019-03-21 Sudakshina Das <sudi.das@arm.com> * elf-bfd.h (struct elf_backend_data): Add argument to merge_gnu_properties. * elf-properties.c (elf_merge_gnu_properties): Add argument to itself and while calling bed->merge_gnu_properties. (elf_merge_gnu_property_list): Update the calls for elf_merge_gnu_properties. * elfnn-aarch64.c (elfNN_aarch64_merge_gnu_properties): Update handling of --force-bti warning and add argument. * elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Add warning. * elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Add argument. * elfxx-x86.h (_bfd_x86_elf_merge_gnu_properties): Likewise in declaration. *** ld/ChangeLog *** 2019-03-21 Sudakshina Das <sudi.das@arm.com> * testsuite/ld-aarch64/aarch64-elf.exp: Add new test. * testsuite/ld-aarch64/bti-plt-1.s: Add .ifdef for PAC note section. * testsuite/ld-aarch64/bti-plt-6.d: Update warning. * testsuite/ld-aarch64/bti-plt-7.d: Likewise. * testsuite/ld-aarch64/bti-warn.d: New test.
1 parent f84bd46 commit 4e53911

File tree

13 files changed

+93
-18
lines changed

13 files changed

+93
-18
lines changed

bfd/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2019-03-21 Sudakshina Das <sudi.das@arm.com>
2+
3+
* elf-bfd.h (struct elf_backend_data): Add argument to
4+
merge_gnu_properties.
5+
* elf-properties.c (elf_merge_gnu_properties): Add argument to
6+
itself and while calling bed->merge_gnu_properties.
7+
(elf_merge_gnu_property_list): Update the calls for
8+
elf_merge_gnu_properties.
9+
* elfnn-aarch64.c (elfNN_aarch64_merge_gnu_properties): Update handling
10+
of --force-bti warning and add argument.
11+
* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Add
12+
warning.
13+
* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Add argument.
14+
* elfxx-x86.h (_bfd_x86_elf_merge_gnu_properties): Likewise in
15+
declaration.
16+
117
2019-03-20 Sudakshina Das <sudi.das@arm.com>
218

319
* elfxx-aarch64.c (_bfd_aarch64_elf_link_fixup_gnu_properties): Define.

bfd/elf-bfd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ struct elf_backend_data
14731473
unsigned int);
14741474

14751475
/* Merge GNU properties. Return TRUE if property is updated. */
1476-
bfd_boolean (*merge_gnu_properties) (struct bfd_link_info *, bfd *,
1476+
bfd_boolean (*merge_gnu_properties) (struct bfd_link_info *, bfd *, bfd *,
14771477
elf_property *, elf_property *);
14781478

14791479
/* Set up GNU properties. */

bfd/elf-properties.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
198198
with ABFD. */
199199

200200
static bfd_boolean
201-
elf_merge_gnu_properties (struct bfd_link_info *info, bfd *abfd,
201+
elf_merge_gnu_properties (struct bfd_link_info *info, bfd *abfd, bfd *bbfd,
202202
elf_property *aprop, elf_property *bprop)
203203
{
204204
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
@@ -207,7 +207,7 @@ elf_merge_gnu_properties (struct bfd_link_info *info, bfd *abfd,
207207
if (bed->merge_gnu_properties != NULL
208208
&& pr_type >= GNU_PROPERTY_LOPROC
209209
&& pr_type < GNU_PROPERTY_LOUSER)
210-
return bed->merge_gnu_properties (info, abfd, aprop, bprop);
210+
return bed->merge_gnu_properties (info, abfd, bbfd, aprop, bprop);
211211

212212
switch (pr_type)
213213
{
@@ -289,7 +289,7 @@ elf_merge_gnu_property_list (struct bfd_link_info *info, bfd *first_pbfd,
289289
TRUE);
290290
/* Pass NULL to elf_merge_gnu_properties for the property which
291291
isn't on *LISTP. */
292-
elf_merge_gnu_properties (info, first_pbfd, &p->property, pr);
292+
elf_merge_gnu_properties (info, first_pbfd, abfd, &p->property, pr);
293293
if (p->property.pr_kind == property_remove)
294294
{
295295
if (info->has_map_file)
@@ -365,7 +365,7 @@ elf_merge_gnu_property_list (struct bfd_link_info *info, bfd *first_pbfd,
365365
else
366366
number_p = FALSE;
367367

368-
if (elf_merge_gnu_properties (info, first_pbfd, NULL, &p->property))
368+
if (elf_merge_gnu_properties (info, first_pbfd, abfd, NULL, &p->property))
369369
{
370370
if (p->property.pr_type == GNU_PROPERTY_NO_COPY_ON_PROTECTED)
371371
elf_has_no_copy_on_protected (first_pbfd) = TRUE;

bfd/elfnn-aarch64.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9968,7 +9968,7 @@ elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info *info)
99689968
for the effect of GNU properties of the output_bfd. */
99699969
static bfd_boolean
99709970
elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info,
9971-
bfd *abfd,
9971+
bfd *abfd, bfd *bbfd,
99729972
elf_property *aprop,
99739973
elf_property *bprop)
99749974
{
@@ -9977,17 +9977,26 @@ elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info,
99779977

99789978
/* If output has been marked with BTI using command line argument, give out
99799979
warning if necessary. */
9980-
if ((prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
9980+
/* Properties are merged per type, hence only check for warnings when merging
9981+
GNU_PROPERTY_AARCH64_FEATURE_1_AND. */
9982+
if (((aprop && aprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
9983+
|| (bprop && bprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND))
9984+
&& (prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
99819985
&& (!elf_aarch64_tdata (info->output_bfd)->no_bti_warn))
99829986
{
99839987
if ((aprop && !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
9984-
|| (bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
9985-
/* If either property is NULL, it means its bfd did not have any
9986-
property. */
9987-
|| !aprop || !bprop)
9988+
|| !aprop)
99889989
{
9989-
_bfd_error_handler (_("warning: BTI turned on by --force-bti when "
9990-
"all inputs do not have BTI in NOTE section."));
9990+
_bfd_error_handler (_("%pB: warning: BTI turned on by --force-bti when "
9991+
"all inputs do not have BTI in NOTE section."),
9992+
abfd);
9993+
}
9994+
if ((bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
9995+
|| !bprop)
9996+
{
9997+
_bfd_error_handler (_("%pB: warning: BTI turned on by --force-bti when "
9998+
"all inputs do not have BTI in NOTE section."),
9999+
bbfd);
999110000
}
999210001
}
999310002

bfd/elfxx-aarch64.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,11 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
719719
prop = _bfd_elf_get_property (ebfd,
720720
GNU_PROPERTY_AARCH64_FEATURE_1_AND,
721721
4);
722+
if (gnu_prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI
723+
&& !(prop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
724+
_bfd_error_handler (_("%pB: warning: BTI turned on by --force-bti "
725+
"when all inputs do not have BTI in NOTE "
726+
"section."), ebfd);
722727
prop->u.number |= gnu_prop;
723728
prop->pr_kind = property_number;
724729

bfd/elfxx-x86.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,7 @@ _bfd_x86_elf_parse_gnu_properties (bfd *abfd, unsigned int type,
24012401
bfd_boolean
24022402
_bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
24032403
bfd *abfd ATTRIBUTE_UNUSED,
2404+
bfd *bbfd ATTRIBUTE_UNUSED,
24042405
elf_property *aprop,
24052406
elf_property *bprop)
24062407
{

bfd/elfxx-x86.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ extern enum elf_property_kind _bfd_x86_elf_parse_gnu_properties
691691
(bfd *, unsigned int, bfd_byte *, unsigned int);
692692

693693
extern bfd_boolean _bfd_x86_elf_merge_gnu_properties
694-
(struct bfd_link_info *, bfd *, elf_property *, elf_property *);
694+
(struct bfd_link_info *, bfd *, bfd *, elf_property *, elf_property *);
695695

696696
extern void _bfd_x86_elf_link_fixup_gnu_properties
697697
(struct bfd_link_info *, elf_property_list **);

ld/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-03-21 Sudakshina Das <sudi.das@arm.com>
2+
3+
* testsuite/ld-aarch64/aarch64-elf.exp: Add new test.
4+
* testsuite/ld-aarch64/bti-plt-1.s: Add .ifdef for PAC note section.
5+
* testsuite/ld-aarch64/bti-plt-6.d: Update warning.
6+
* testsuite/ld-aarch64/bti-plt-7.d: Likewise.
7+
* testsuite/ld-aarch64/bti-warn.d: New test.
8+
19
2019-03-21 Alan Modra <amodra@gmail.com>
210

311
* testsuite/ld-elf/fini2.s: Reduce alignment.

ld/testsuite/ld-aarch64/aarch64-elf.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,5 @@ run_dump_test "pac-plt-1"
407407
run_dump_test "pac-plt-2"
408408
run_dump_test "bti-pac-plt-1"
409409
run_dump_test "bti-pac-plt-2"
410+
411+
run_dump_test "bti-warn"

ld/testsuite/ld-aarch64/bti-plt-1.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ _start:
2121
.p2align 3
2222
5:
2323
.endif
24+
.ifdef __property_pac__
25+
.section ".note.gnu.property", "a"
26+
.p2align 3
27+
.long 1f - 0f /* name length */
28+
.long 5f - 2f /* data length */
29+
.long 5 /* note type */
30+
0: .asciz "GNU" /* vendor name */
31+
1:
32+
.p2align 3
33+
2: .long 0xc0000000 /* pr_type. */
34+
.long 4f - 3f /* pr_datasz. */
35+
3:
36+
.long 0x2 /* PAC. */
37+
4:
38+
.p2align 3
39+
5:
40+
.endif

0 commit comments

Comments
 (0)