On Thu, Nov 22, 2018 at 8:47 PM Jakub Jelinek <[email protected]> wrote:
>
> Hi!
>
> While adjusting the PR85644 patch, I've noticed that while pretty much
> the whole ix86_option_override_internal works only with opts_set->x_
> and opts->x_, the stack protector guard code was accessing
> global_options_set.x_ or using the macros that expand to
> global_options.x_ . While it is probably not breaking anything because
> the target attribute doesn't (at least so far) allow any of these options,
> it looks inconsistent with the rest.
>
> So, the following patch adjusts it to do what the rest of
> ix86_option_override_internal is doing.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-11-22 Jakub Jelinek <[email protected]>
>
> * config/i386/i386.c (ix86_option_override_internal): For
> stack_protector_guard related options, use opts_set->x_ instead
> of global_options_set. and prefix options with opts->x_ . Move
> defaults for offset and reg into else block.
OK.
Thanks,
Uros.
> --- gcc/config/i386/i386.c.jj 2018-11-22 10:44:32.767690142 +0100
> +++ gcc/config/i386/i386.c 2018-11-22 11:35:08.294512244 +0100
> @@ -4568,14 +4568,10 @@ ix86_option_override_internal (bool main
> opts->x_ix86_stack_protector_guard = SSP_GLOBAL;
> }
>
> -#ifdef TARGET_THREAD_SSP_OFFSET
> - ix86_stack_protector_guard_offset = TARGET_THREAD_SSP_OFFSET;
> -#endif
> -
> - if (global_options_set.x_ix86_stack_protector_guard_offset_str)
> + if (opts_set->x_ix86_stack_protector_guard_offset_str)
> {
> char *endp;
> - const char *str = ix86_stack_protector_guard_offset_str;
> + const char *str = opts->x_ix86_stack_protector_guard_offset_str;
>
> errno = 0;
> int64_t offset;
> @@ -4595,20 +4591,16 @@ ix86_option_override_internal (bool main
> error ("%qs is not a valid offset "
> "in -mstack-protector-guard-offset=", str);
>
> - ix86_stack_protector_guard_offset = offset;
> + opts->x_ix86_stack_protector_guard_offset = offset;
> }
> +#ifdef TARGET_THREAD_SSP_OFFSET
> + else
> + opts->x_ix86_stack_protector_guard_offset = TARGET_THREAD_SSP_OFFSET;
> +#endif
>
> - ix86_stack_protector_guard_reg = DEFAULT_TLS_SEG_REG;
> -
> - /* The kernel uses a different segment register for performance
> - reasons; a system call would not have to trash the userspace
> - segment register, which would be expensive. */
> - if (ix86_cmodel == CM_KERNEL)
> - ix86_stack_protector_guard_reg = ADDR_SPACE_SEG_GS;
> -
> - if (global_options_set.x_ix86_stack_protector_guard_reg_str)
> + if (opts_set->x_ix86_stack_protector_guard_reg_str)
> {
> - const char *str = ix86_stack_protector_guard_reg_str;
> + const char *str = opts->x_ix86_stack_protector_guard_reg_str;
> addr_space_t seg = ADDR_SPACE_GENERIC;
>
> /* Discard optional register prefix. */
> @@ -4626,9 +4618,19 @@ ix86_option_override_internal (bool main
> if (seg == ADDR_SPACE_GENERIC)
> error ("%qs is not a valid base register "
> "in -mstack-protector-guard-reg=",
> - ix86_stack_protector_guard_reg_str);
> + opts->x_ix86_stack_protector_guard_reg_str);
> +
> + opts->x_ix86_stack_protector_guard_reg = seg;
> + }
> + else
> + {
> + opts->x_ix86_stack_protector_guard_reg = DEFAULT_TLS_SEG_REG;
>
> - ix86_stack_protector_guard_reg = seg;
> + /* The kernel uses a different segment register for performance
> + reasons; a system call would not have to trash the userspace
> + segment register, which would be expensive. */
> + if (opts->x_ix86_cmodel == CM_KERNEL)
> + opts->x_ix86_stack_protector_guard_reg = ADDR_SPACE_SEG_GS;
> }
>
> /* Handle -mmemcpy-strategy= and -mmemset-strategy= */
>
> Jakub