From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1035) id 58E24385C401; Wed, 24 Aug 2022 16:10:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58E24385C401 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Richard Earnshaw To: bfd-cvs@sourceware.org Subject: [binutils-gdb] gas: arm: handle multiple .directives on a single line (PR29519) X-Act-Checkin: binutils-gdb X-Git-Author: Richard Earnshaw X-Git-Refname: refs/heads/master X-Git-Oldrev: 70175292616118bad315296ba6180f375326bb6c X-Git-Newrev: a37854f9162fac592b669eda53f465fc190c9341 Message-Id: <20220824161001.58E24385C401@sourceware.org> Date: Wed, 24 Aug 2022 16:10:01 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Aug 2022 16:10:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da37854f9162f= ac592b669eda53f465fc190c9341 commit a37854f9162fac592b669eda53f465fc190c9341 Author: Richard Earnshaw Date: Wed Aug 24 17:08:07 2022 +0100 gas: arm: handle multiple .directives on a single line (PR29519) =20 There's been a long-standing bug in the arm backend where target-specific directives did not correctly handle lines with multiple statements. This patch fixes the issue for all the cases I've been able to find. =20 It does result in a slight change in behaviour when errors are encountered: where, previously, =20 .cpu arm6 bar =20 would result in the error "junk at end of line, first unrecognized character is `b'", we now get "unknown cpu `arm6 bar'", which I think is slightly more helpful anyway. Similar errors are generated for other directives. Diff: --- gas/config/tc-arm.c | 64 ++++++++++++++++++++++++++--------= ---- gas/testsuite/gas/arm/directives.d | 18 +++++++++++ gas/testsuite/gas/arm/directives.s | 11 +++++++ 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c index 6cdc2db307e..0f7d7695c0e 100644 --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -2851,12 +2851,7 @@ s_unreq (int a ATTRIBUTE_UNUSED) char saved_char; =20 name =3D input_line_pointer; - - while (*input_line_pointer !=3D 0 - && *input_line_pointer !=3D ' ' - && *input_line_pointer !=3D '\n') - ++input_line_pointer; - + input_line_pointer =3D find_end_of_line (input_line_pointer, flag_m68k_m= ri); saved_char =3D *input_line_pointer; *input_line_pointer =3D 0; =20 @@ -3208,6 +3203,7 @@ s_code (int unused ATTRIBUTE_UNUSED) default: as_bad (_("invalid operand to .code directive (%d) (expecting 16 or = 32)"), temp); } + demand_empty_rest_of_line (); } =20 static void @@ -3230,7 +3226,7 @@ s_force_thumb (int ignore ATTRIBUTE_UNUSED) static void s_thumb_func (int ignore ATTRIBUTE_UNUSED) { - s_thumb (0); + s_thumb (0); /* Will check for end-of-line. */ =20 /* The following label is the name/address of the start of a Thumb funct= ion. We need to know this for the interworking support. */ @@ -3781,6 +3777,7 @@ s_ltorg (int ignored ATTRIBUTE_UNUSED) literal_pool * pool; char sym_name[20]; =20 + demand_empty_rest_of_line (); pool =3D find_literal_pool (); if (pool =3D=3D NULL || pool->symbol =3D=3D NULL @@ -33365,11 +33362,17 @@ s_arm_cpu (int ignored ATTRIBUTE_UNUSED) char saved_char; =20 name =3D input_line_pointer; - while (*input_line_pointer && !ISSPACE (*input_line_pointer)) - input_line_pointer++; + input_line_pointer =3D find_end_of_line (input_line_pointer, flag_m68k_m= ri); saved_char =3D *input_line_pointer; *input_line_pointer =3D 0; =20 + if (!*name) + { + as_bad (_(".cpu: missing cpu name")); + *input_line_pointer =3D saved_char; + return; + } + /* Skip the first "all" entry. */ for (opt =3D arm_cpus + 1; opt->name !=3D NULL; opt++) if (streq (opt->name, name)) @@ -33395,7 +33398,6 @@ s_arm_cpu (int ignored ATTRIBUTE_UNUSED) } as_bad (_("unknown cpu `%s'"), name); *input_line_pointer =3D saved_char; - ignore_rest_of_line (); } =20 /* Parse a .arch directive. */ @@ -33408,11 +33410,17 @@ s_arm_arch (int ignored ATTRIBUTE_UNUSED) char *name; =20 name =3D input_line_pointer; - while (*input_line_pointer && !ISSPACE (*input_line_pointer)) - input_line_pointer++; + input_line_pointer =3D find_end_of_line (input_line_pointer, flag_m68k_m= ri); saved_char =3D *input_line_pointer; *input_line_pointer =3D 0; =20 + if (!*name) + { + as_bad (_(".arch: missing architecture name")); + *input_line_pointer =3D saved_char; + return; + } + /* Skip the first "all" entry. */ for (opt =3D arm_archs + 1; opt->name !=3D NULL; opt++) if (streq (opt->name, name)) @@ -33443,11 +33451,17 @@ s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) char *name; =20 name =3D input_line_pointer; - while (*input_line_pointer && !ISSPACE (*input_line_pointer)) - input_line_pointer++; + input_line_pointer =3D find_end_of_line (input_line_pointer, flag_m68k_m= ri); saved_char =3D *input_line_pointer; *input_line_pointer =3D 0; =20 + if (!*name) + { + as_bad (_(".object_arch: missing architecture name")); + *input_line_pointer =3D saved_char; + return; + } + /* Skip the first "all" entry. */ for (opt =3D arm_archs + 1; opt->name !=3D NULL; opt++) if (streq (opt->name, name)) @@ -33474,11 +33488,17 @@ s_arm_arch_extension (int ignored ATTRIBUTE_UNUSE= D) int adding_value =3D 1; =20 name =3D input_line_pointer; - while (*input_line_pointer && !ISSPACE (*input_line_pointer)) - input_line_pointer++; + input_line_pointer =3D find_end_of_line (input_line_pointer, flag_m68k_m= ri); saved_char =3D *input_line_pointer; *input_line_pointer =3D 0; =20 + if (!*name) + { + as_bad (_(".arch_extension: missing architecture extension")); + *input_line_pointer =3D saved_char; + return; + } + if (strlen (name) >=3D 2 && startswith (name, "no")) { @@ -33557,7 +33577,6 @@ s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) as_bad (_("unknown architecture extension `%s'\n"), name); =20 *input_line_pointer =3D saved_char; - ignore_rest_of_line (); } =20 /* Parse a .fpu directive. */ @@ -33570,11 +33589,17 @@ s_arm_fpu (int ignored ATTRIBUTE_UNUSED) char *name; =20 name =3D input_line_pointer; - while (*input_line_pointer && !ISSPACE (*input_line_pointer)) - input_line_pointer++; + input_line_pointer =3D find_end_of_line (input_line_pointer, flag_m68k_m= ri); saved_char =3D *input_line_pointer; *input_line_pointer =3D 0; =20 + if (!*name) + { + as_bad (_(".fpu: missing fpu name")); + *input_line_pointer =3D saved_char; + return; + } + for (opt =3D arm_fpus; opt->name !=3D NULL; opt++) if (streq (opt->name, name)) { @@ -33587,7 +33612,6 @@ s_arm_fpu (int ignored ATTRIBUTE_UNUSED) #endif ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); *input_line_pointer =3D saved_char; - demand_empty_rest_of_line (); return; } =20 diff --git a/gas/testsuite/gas/arm/directives.d b/gas/testsuite/gas/arm/dir= ectives.d new file mode 100644 index 00000000000..66002188a9c --- /dev/null +++ b/gas/testsuite/gas/arm/directives.d @@ -0,0 +1,18 @@ +# name: multiple directives on one line +# source: directives.s +# as: --fatal-warnings +# readelf: -A +# This test is only valid on EABI based ports. +# target: *-*-*eabi* *-*-nacl* + +Attribute Section: aeabi +File Attributes + Tag_CPU_name: "custom_name" + Tag_CPU_arch: v8 + Tag_CPU_arch_profile: Application + Tag_ARM_ISA_use: Yes + Tag_THUMB_ISA_use: Thumb-2 + Tag_FP_arch: FP for ARMv8 + Tag_ABI_align_preserved: 8-byte, except leaf SP + Tag_MPextension_use: Allowed + Tag_Virtualization_use: TrustZone and Virtualization Extensions diff --git a/gas/testsuite/gas/arm/directives.s b/gas/testsuite/gas/arm/dir= ectives.s new file mode 100644 index 00000000000..c5947415e09 --- /dev/null +++ b/gas/testsuite/gas/arm/directives.s @@ -0,0 +1,11 @@ +@ Check that various arm-specific directives can appear on the same line + .cpu cortex-a5 ; .arch armv8-a ; .arch_extension fp ; .arch_extension nos= imd ; .syntax unified ; .thumb; .code 16 ; movs r0, r1 + t1 .req r1 ; t2 .req r2 ; + movs t1, t2 @ mov r1, r2 + + .unreq t1;.unreq t2; + t1 .req r2 + t2 .req r3 + movs t1, t2 @ movs r2, r3 + vmov.f32 s0, s1 + .eabi_attribute Tag_CPU_name, "custom_name" ; .eabi_attribute Tag_ABI_ali= gn8_preserved, 1;