View | Details | Return to bug 81708 | Differences between
and this patch

Collapse All | Expand All

(-)a/gcc/config/i386/i386.c (-14 / +66 lines)
Lines 6662-6667 ix86_option_override_internal (bool main_args_p, Link Here
6662
    opts->x_ix86_stack_protector_guard
6662
    opts->x_ix86_stack_protector_guard
6663
      = TARGET_HAS_BIONIC ? SSP_GLOBAL : SSP_TLS;
6663
      = TARGET_HAS_BIONIC ? SSP_GLOBAL : SSP_TLS;
6664
6664
6665
#ifdef TARGET_THREAD_SSP_OFFSET
6666
  ix86_stack_protector_guard_offset = TARGET_THREAD_SSP_OFFSET;
6667
#endif
6668
6669
  if (global_options_set.x_ix86_stack_protector_guard_offset_str)
6670
    {
6671
      char *endp;
6672
      const char *str = ix86_stack_protector_guard_offset_str;
6673
6674
      errno = 0;
6675
      int64_t offset;
6676
6677
#if defined(INT64_T_IS_LONG)
6678
      offset = strtol (str, &endp, 0);
6679
#else
6680
      offset = strtoll (str, &endp, 0);
6681
#endif
6682
6683
      if (!*str || *endp || errno)
6684
	error ("%qs is not a valid number "
6685
	       "in -mstack-protector-guard-offset=", str);
6686
6687
      if (!IN_RANGE (offset, HOST_WIDE_INT_C (-0x80000000),
6688
		     HOST_WIDE_INT_C (0x7fffffff)))
6689
	error ("%qs is not a valid offset "
6690
	       "in -mstack-protector-guard-offset=", str);
6691
6692
      ix86_stack_protector_guard_offset = offset;
6693
    }
6694
6695
  ix86_stack_protector_guard_reg = DEFAULT_TLS_SEG_REG;
6696
6697
  /* The kernel uses a different segment register for performance
6698
     reasons; a system call would not have to trash the userspace
6699
     segment register, which would be expensive.  */
6700
  if (ix86_cmodel == CM_KERNEL)
6701
    ix86_stack_protector_guard_reg = ADDR_SPACE_SEG_GS;
6702
6703
  if (global_options_set.x_ix86_stack_protector_guard_reg_str)
6704
    {
6705
      const char *str = ix86_stack_protector_guard_reg_str;
6706
      addr_space_t seg = ADDR_SPACE_GENERIC;
6707
6708
      /* Discard optional register prefix.  */
6709
      if (str[0] == '%')
6710
	str++;
6711
6712
      if (str[1] == 's' && str[2] == '\0')
6713
	{
6714
	  if (str[0] == 'f')
6715
	    seg = ADDR_SPACE_SEG_FS;
6716
	  else if (str[0] == 'g')
6717
	    seg = ADDR_SPACE_SEG_GS;
6718
	}
6719
6720
      if (seg == ADDR_SPACE_GENERIC)
6721
	error ("%qs is not a valid base register "
6722
	       "in -mstack-protector-guard-reg=",
6723
	       ix86_stack_protector_guard_reg_str);
6724
6725
      ix86_stack_protector_guard_reg = seg;
6726
    }
6727
6665
  /* Handle -mmemcpy-strategy= and -mmemset-strategy=  */
6728
  /* Handle -mmemcpy-strategy= and -mmemset-strategy=  */
6666
  if (opts->x_ix86_tune_memcpy_strategy)
6729
  if (opts->x_ix86_tune_memcpy_strategy)
6667
    {
6730
    {
Lines 45795-45821 ix86_mangle_type (const_tree type) Link Here
45795
    }
45858
    }
45796
}
45859
}
45797
45860
45798
#ifdef TARGET_THREAD_SSP_OFFSET
45799
static tree
45861
static tree
45800
ix86_stack_protect_guard (void)
45862
ix86_stack_protect_guard (void)
45801
{
45863
{
45802
  if (TARGET_SSP_TLS_GUARD)
45864
  if (TARGET_SSP_TLS_GUARD)
45803
    {
45865
    {
45804
      tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1);
45866
      tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1);
45805
      addr_space_t as = DEFAULT_TLS_SEG_REG;
45806
45867
45807
      /* The kernel uses a different segment register for performance
45868
      int qual = ENCODE_QUAL_ADDR_SPACE (ix86_stack_protector_guard_reg);
45808
	 reasons; a system call would not have to trash the userspace
45809
	 segment register, which would be expensive.  */
45810
      if (ix86_cmodel == CM_KERNEL)
45811
	as = ADDR_SPACE_SEG_GS;
45812
45813
      int qual = ENCODE_QUAL_ADDR_SPACE (as);
45814
45869
45815
      tree type = build_qualified_type (type_node, qual);
45870
      tree type = build_qualified_type (type_node, qual);
45816
      tree asptrtype = build_pointer_type (type);
45871
      tree asptrtype = build_pointer_type (type);
45817
      tree sspoff = build_int_cst (asptrtype, TARGET_THREAD_SSP_OFFSET);
45872
      tree sspoff = build_int_cst (asptrtype,
45818
45873
				   ix86_stack_protector_guard_offset);
45819
      tree t = build2 (MEM_REF, asptrtype, sspoff,
45874
      tree t = build2 (MEM_REF, asptrtype, sspoff,
45820
		       build_int_cst (asptrtype, 0));
45875
		       build_int_cst (asptrtype, 0));
45821
      return t;
45876
      return t;
Lines 45823-45829 ix86_stack_protect_guard (void) Link Here
45823
45878
45824
  return default_stack_protect_guard ();
45879
  return default_stack_protect_guard ();
45825
}
45880
}
45826
#endif
45827
45881
45828
/* For 32-bit code we can save PIC register setup by using
45882
/* For 32-bit code we can save PIC register setup by using
45829
   __stack_chk_fail_local hidden function instead of calling
45883
   __stack_chk_fail_local hidden function instead of calling
Lines 52831-52840 ix86_run_selftests (void) Link Here
52831
#undef TARGET_MANGLE_TYPE
52885
#undef TARGET_MANGLE_TYPE
52832
#define TARGET_MANGLE_TYPE ix86_mangle_type
52886
#define TARGET_MANGLE_TYPE ix86_mangle_type
52833
52887
52834
#ifdef TARGET_THREAD_SSP_OFFSET
52835
#undef TARGET_STACK_PROTECT_GUARD
52888
#undef TARGET_STACK_PROTECT_GUARD
52836
#define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
52889
#define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
52837
#endif
52838
52890
52839
#if !TARGET_MACHO
52891
#if !TARGET_MACHO
52840
#undef TARGET_STACK_PROTECT_FAIL
52892
#undef TARGET_STACK_PROTECT_FAIL
(-)a/gcc/config/i386/i386.opt (+14 lines)
Lines 924-929 Enum(stack_protector_guard) String(tls) Value(SSP_TLS) Link Here
924
EnumValue
924
EnumValue
925
Enum(stack_protector_guard) String(global) Value(SSP_GLOBAL)
925
Enum(stack_protector_guard) String(global) Value(SSP_GLOBAL)
926
926
927
mstack-protector-guard-offset=
928
Target RejectNegative Joined Integer Var(ix86_stack_protector_guard_offset_str)
929
Use the given offset for addressing the stack-protector guard.
930
931
TargetVariable
932
HOST_WIDE_INT ix86_stack_protector_guard_offset = 0
933
934
mstack-protector-guard-reg=
935
Target RejectNegative Joined Var(ix86_stack_protector_guard_reg_str)
936
Use the given base register for addressing the stack-protector guard.
937
938
TargetVariable
939
addr_space_t ix86_stack_protector_guard_reg = ADDR_SPACE_GENERIC
940
927
mmitigate-rop
941
mmitigate-rop
928
Target Var(flag_mitigate_rop) Init(0)
942
Target Var(flag_mitigate_rop) Init(0)
929
Attempt to avoid generating instruction sequences containing ret bytes.
943
Attempt to avoid generating instruction sequences containing ret bytes.

Return to bug 81708