[PATCH, gas/ARM] Clean up selection of feature bits

Thomas Preudhomme thomas.preudhomme@foss.arm.com
Tue Feb 27 13:59:00 GMT 2018


I've always found the code in ARM backend of gas to control what
CPU/architecture and FPU are selected by the user and to support
autodetection of features complex and confusing. Chief among the
issues I have with that code is the lack of comments to explain
the meaning of the various variables. This patch addresses that
and much more:

- add comments to explain meaning of all arm_feature_set variables
- keep track of currently selected CPU, extensions and FPU in a separate
   set of new variables
- make naming of variable more consistent
- remove dead code
- simplify handling of extensions

The overall approach is as follows:

* restrict m*_opt variable to hold the feature bits of the
   corresponding mcpu/march/mfpu command-line options
* record selected CPU, extensions and FPU in new selected_* during
   md_begin
* whenever a .cpu/.arch/.arch_extension/.fpu directive is met, update
   the corresponding selected_* variables (eg. selected_arch, then
   selected_cpu for a .cpu or .arch directive) and then finally
   cpu_variant from them
* pass extension feature set pointer by value to arm_parse_extension
   since it's only ever called from arm_parse_cpu and arm_parse_arch
   which allocate the extension feature set themselves
* likewise, remove allocation from s_arm_arch_extension since the use
   of arm_feature_set structure for selected_ext rather than a pointer
   alleviate the need for it
* in autodetection mode, only set all CPU fits in cpu_variant but leave
   selected_cpu* variables unset
* in md_begin, remove dead "else if" to set a default FPU when no FPU
   was selected. Setting a default FPU based on CPU as did the code
   before it turn dead should be based on the default FPU field of the
   CPU and architecture table as will be done in a separate patch. Logic
   is wrong anyway since it sets VFP2 as default FPU for Armv6-M and
   Armv7-M

Hopefully that should be enough to understand the change but if not feel
free to ask questions about the patch. While I believe the new code is
easier to understand, it remains complex and the old one was even more
complex so the change is difficult to understand.

ChangeLog entry is as follows:

*** gas/ChangeLog ***

2018-02-21  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* config/tc-arm.c (cpu_variant, arm_arch_used, thumb_arch_used,
	legacy_cpu, legacy_fpu, mcpu_cpu_opt, dyn_mcpu_ext_opt,
	mcpu_fpu_opt, march_cpu_opt, dyn_march_ext_opt, march_fpu_opt,
	mfpu_opt, object_arch, selected_cpu): Comment meaning of variables.
	(dyn_mcpu_ext_opt): Also rename into ...
	(mcpu_ext_opt): This.
	(dyn_march_ext_opt): Also rename into ...
	(march_ext_opt): This.
	(object_arch): Also rename into ...
	(selected_object_arch): This and make it a plain arm_feature_set
	structure.
	(selected_arch, selected_ext, selected_fpu): New static variables.
	(do_bx): Adapt to change in name and type of object_arch.
	(md_begin): Set selected_arch rather than mcpu_cpu_opt, selected_ext
	rather than dyn_mcpu_ext_opt and selected_fpu rather than mfpu_opt.
	Remove dead code to set default FPU if architecture version is greater
	than 5.  Set all CPU bits of cpu_variant directly in autodection
	leaving mcpu_cpu_opt, selected_arch and selected_cpu unset.
	(arm_parse_extension): Take extension feature set pointer
	parameter by value rather than by pointer.  Remove allocation
	code.  Adapt code accordingly.
	(arm_parse_cpu): Adapt to variable renaming and changes in
	arm_parse_extension () signature.
	(arm_parse_arch): Likewise.
	(aeabi_set_public_attributes): Also set selected_arch and selected_ext
	in addition to selected_cpu.  Set flags_arch and flags_ext from them
	instead of selected_cpu.  Adapt to variables renaming and type change.
	(arm_md_post_relax): Adapt to variable renaming.
	(s_arm_cpu): Set selcted_cpu_cpu and selected_ext instead of
	mcpu_cpu_opt and dyn_mcpu_ext_opt.  Set selected_cpu from them
	and cpu_variant from selected_cpu and selected_fpu.
	(s_arm_arch): Likewise.
	(s_arm_object_arch): Adapt to variable renaming.
	(s_arm_arch_extension): Use ARM_CPU_IS_ANY instead of checking
	feature set against arm_any.  Check selected_arch rather than
	*mcpu_cpu_opt.  Set selected_ext rather than *dyn_mcpu_ext_opt and
	remove allocation code.
	(s_arm_fpu): Set selected_fpu instead of mfpu_opt.  Set all CPU
	feature bits if in autodetection mode.

Testing: Built binutils targeting arm-none-eabi and testsuite shows no
regression.

Ok for master?

Best regards,

Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cleanup_selection_feature_bits.patch
Type: text/x-patch
Size: 16411 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20180227/b99cdbe8/attachment.bin>


More information about the Binutils mailing list