From: Jakub Jelinek Date: Fri, 8 Jan 2021 11:28:25 +0000 (+0100) Subject: i386: Fix -mcmodel= vs. target attribute [PR98585] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f1cb70d7ca6a8da7f6bc7f43fb5e758c0ce88b5;p=gcc.git i386: Fix -mcmodel= vs. target attribute [PR98585] My patch to save/restore opts_set rather than essentially treating global_options_set as a logical or whether some option has ever been explicitly set somewhere apparently broke -mcmodel= vs. target attribute (and as the patch shows some other options too). The thing is, at least for options for which we ever test opts_set->x_* or global_options_set.x_*, we need to save/restore them next to the saving/restoring of the actual option values. If an option has Save keyword or in case of TargetVariable, it is the generic code that handles the saving and restoring of both the option and corresponding opts_set flag automatically, for other variables (TargetSave, or Target without Save) the backend needs to do that in the target hook manually and in that case should save/restore both the option values (the hooks mostly did that) and opts_set (they didn't). As it seems much easier to let the automatic saving/restoring do the work for us unless the saving/restoring of the option needs some specific magic, the following patch is a result of grepping through the backend for opts_set->x_ and global_options_set.x_ and for all such referenced variables, grepping whether it is saved/restored including opts_set properly in the generated options-save.c or not. 2021-01-08 Jakub Jelinek PR target/98585 * config/i386/i386.opt (ix86_cmodel, ix86_incoming_stack_boundary_arg, ix86_pmode, ix86_preferred_stack_boundary_arg, ix86_regparm, ix86_veclibabi_type): Remove x_ prefix, use TargetVariable instead of TargetSave and initialize for variables with enum types. (mfentry, mstack-protector-guard-reg=, mstack-protector-guard-offset=, mstack-protector-guard-symbol=): Add Save. * config/i386/i386-options.c (ix86_function_specific_save, ix86_function_specific_restore): Don't save or restore x_ix86_cmodel, x_ix86_incoming_stack_boundary_arg, x_ix86_pmode, x_ix86_preferred_stack_boundary_arg, x_ix86_regparm, x_ix86_veclibabi_type. * gcc.target/i386/pr98585.c: New test. --- diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c index c22dd1de9bc..6afd7a9b1f2 100644 --- a/gcc/config/i386/i386-options.c +++ b/gcc/config/i386/i386-options.c @@ -651,18 +651,13 @@ ix86_function_specific_save (struct cl_target_option *ptr, ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit; ptr->x_ix86_arch_string = opts->x_ix86_arch_string; ptr->x_ix86_tune_string = opts->x_ix86_tune_string; - ptr->x_ix86_cmodel = opts->x_ix86_cmodel; ptr->x_ix86_abi = opts->x_ix86_abi; ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect; ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost; ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes; ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer; ptr->x_ix86_force_drap = opts->x_ix86_force_drap; - ptr->x_ix86_incoming_stack_boundary_arg = opts->x_ix86_incoming_stack_boundary_arg; - ptr->x_ix86_pmode = opts->x_ix86_pmode; - ptr->x_ix86_preferred_stack_boundary_arg = opts->x_ix86_preferred_stack_boundary_arg; ptr->x_ix86_recip_name = opts->x_ix86_recip_name; - ptr->x_ix86_regparm = opts->x_ix86_regparm; ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold; ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx; ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard; @@ -672,7 +667,6 @@ ix86_function_specific_save (struct cl_target_option *ptr, ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy; ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy; ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default; - ptr->x_ix86_veclibabi_type = opts->x_ix86_veclibabi_type; /* The fields are char but the variables are not; make sure the values fit in the fields. */ @@ -788,18 +782,13 @@ ix86_function_specific_restore (struct gcc_options *opts, opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit; opts->x_ix86_arch_string = ptr->x_ix86_arch_string; opts->x_ix86_tune_string = ptr->x_ix86_tune_string; - opts->x_ix86_cmodel = ptr->x_ix86_cmodel; opts->x_ix86_abi = ptr->x_ix86_abi; opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect; opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost; opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes; opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer; opts->x_ix86_force_drap = ptr->x_ix86_force_drap; - opts->x_ix86_incoming_stack_boundary_arg = ptr->x_ix86_incoming_stack_boundary_arg; - opts->x_ix86_pmode = ptr->x_ix86_pmode; - opts->x_ix86_preferred_stack_boundary_arg = ptr->x_ix86_preferred_stack_boundary_arg; opts->x_ix86_recip_name = ptr->x_ix86_recip_name; - opts->x_ix86_regparm = ptr->x_ix86_regparm; opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold; opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx; opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard; @@ -809,7 +798,6 @@ ix86_function_specific_restore (struct gcc_options *opts, opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy; opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy; opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default; - opts->x_ix86_veclibabi_type = ptr->x_ix86_veclibabi_type; ix86_tune_cost = processor_cost_table[ix86_tune]; /* TODO: ix86_cost should be chosen at instruction or function granuality so for cold code we use size_cost even in !optimize_size compilation. */ diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index 0bfad73a3c9..c781fdc8278 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -105,8 +105,8 @@ TargetSave unsigned char arch_specified ;; -mcmodel= model -TargetSave -enum cmodel x_ix86_cmodel +TargetVariable +enum cmodel ix86_cmodel = CM_32 ;; -mabi= TargetSave @@ -133,24 +133,24 @@ TargetSave int x_ix86_force_drap ;; -mincoming-stack-boundary= -TargetSave -int x_ix86_incoming_stack_boundary_arg +TargetVariable +int ix86_incoming_stack_boundary_arg ;; -maddress-mode= -TargetSave -enum pmode x_ix86_pmode +TargetVariable +enum pmode ix86_pmode = PMODE_SI ;; -mpreferred-stack-boundary= -TargetSave -int x_ix86_preferred_stack_boundary_arg +TargetVariable +int ix86_preferred_stack_boundary_arg ;; -mrecip= TargetSave const char *x_ix86_recip_name ;; -mregparm= -TargetSave -int x_ix86_regparm +TargetVariable +int ix86_regparm ;; -mlarge-data-threshold= TargetSave @@ -189,8 +189,8 @@ TargetSave int x_ix86_tune_no_default ;; -mveclibabi= -TargetSave -enum ix86_veclibabi x_ix86_veclibabi_type +TargetVariable +enum ix86_veclibabi ix86_veclibabi_type = ix86_veclibabi_type_none ;; x86 options m128bit-long-double @@ -934,7 +934,7 @@ Target Mask(ISA_PREFETCHWT1) Var(ix86_isa_flags) Save Support PREFETCHWT1 built-in functions and code generation. mfentry -Target Var(flag_fentry) +Target Save Var(flag_fentry) Emit profiling counter call at function entry before prologue. mrecord-mcount @@ -1005,21 +1005,21 @@ EnumValue Enum(stack_protector_guard) String(global) Value(SSP_GLOBAL) mstack-protector-guard-reg= -Target RejectNegative Joined Var(ix86_stack_protector_guard_reg_str) +Target Save RejectNegative Joined Var(ix86_stack_protector_guard_reg_str) Use the given base register for addressing the stack-protector guard. TargetVariable addr_space_t ix86_stack_protector_guard_reg = ADDR_SPACE_GENERIC mstack-protector-guard-offset= -Target RejectNegative Joined Integer Var(ix86_stack_protector_guard_offset_str) +Target Save RejectNegative Joined Integer Var(ix86_stack_protector_guard_offset_str) Use the given offset for addressing the stack-protector guard. TargetVariable HOST_WIDE_INT ix86_stack_protector_guard_offset = 0 mstack-protector-guard-symbol= -Target RejectNegative Joined Integer Var(ix86_stack_protector_guard_symbol_str) +Target Save RejectNegative Joined Integer Var(ix86_stack_protector_guard_symbol_str) Use the given symbol for addressing the stack-protector guard. mmitigate-rop diff --git a/gcc/testsuite/gcc.target/i386/pr98585.c b/gcc/testsuite/gcc.target/i386/pr98585.c new file mode 100644 index 00000000000..18325f5b96d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98585.c @@ -0,0 +1,14 @@ +/* PR target/98585 */ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-O2 -mcmodel=large -masm=att" } */ +/* { dg-final { scan-assembler "movabs\[^\n\r]*bar" } } */ + +void bar (void); + +void +__attribute__ ((target ("bmi2"))) +foo() +{ + bar (); +}