@@ -1426,7 +1426,7 @@ elf_x86_64_need_pic (struct bfd_link_info *info,
1426
1426
break ;
1427
1427
}
1428
1428
1429
- if (!h -> def_regular && !h -> def_dynamic )
1429
+ if (!SYMBOL_DEFINED_NON_SHARED_P ( h ) && !h -> def_dynamic )
1430
1430
und = _ ("undefined " );
1431
1431
}
1432
1432
else
@@ -1855,6 +1855,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1855
1855
const char * name ;
1856
1856
bfd_boolean size_reloc ;
1857
1857
bfd_boolean converted_reloc ;
1858
+ bfd_boolean do_check_pic ;
1858
1859
1859
1860
r_symndx = htab -> r_sym (rel -> r_info );
1860
1861
r_type = ELF32_R_TYPE (rel -> r_info );
@@ -2130,6 +2131,13 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2130
2131
size_reloc = TRUE;
2131
2132
goto do_size ;
2132
2133
2134
+ case R_X86_64_PC8 :
2135
+ case R_X86_64_PC16 :
2136
+ case R_X86_64_PC32 :
2137
+ case R_X86_64_PC32_BND :
2138
+ do_check_pic = TRUE;
2139
+ goto check_pic ;
2140
+
2133
2141
case R_X86_64_32 :
2134
2142
if (!ABI_64_P (abfd ))
2135
2143
goto pointer ;
@@ -2153,13 +2161,11 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2153
2161
& x86_64_elf_howto_table [r_type ]);
2154
2162
/* Fall through. */
2155
2163
2156
- case R_X86_64_PC8 :
2157
- case R_X86_64_PC16 :
2158
- case R_X86_64_PC32 :
2159
- case R_X86_64_PC32_BND :
2160
2164
case R_X86_64_PC64 :
2161
2165
case R_X86_64_64 :
2162
2166
pointer :
2167
+ do_check_pic = FALSE;
2168
+ check_pic :
2163
2169
if (eh != NULL && (sec -> flags & SEC_CODE ) != 0 )
2164
2170
eh -> zero_undefweak |= 0x2 ;
2165
2171
/* We are called after all symbols have been resolved. Only
@@ -2223,6 +2229,67 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2223
2229
}
2224
2230
}
2225
2231
2232
+ if (do_check_pic )
2233
+ {
2234
+ /* Don't complain about -fPIC if the symbol is undefined
2235
+ when building executable unless it is unresolved weak
2236
+ symbol, references a dynamic definition in PIE or
2237
+ -z nocopyreloc is used. */
2238
+ bfd_boolean no_copyreloc_p
2239
+ = (info -> nocopyreloc
2240
+ || (h != NULL
2241
+ && eh -> def_protected
2242
+ && elf_has_no_copy_on_protected (h -> root .u .def .section -> owner )));
2243
+ if ((sec -> flags & SEC_ALLOC ) != 0
2244
+ && (sec -> flags & SEC_READONLY ) != 0
2245
+ && h != NULL
2246
+ && ((bfd_link_executable (info )
2247
+ && ((h -> root .type == bfd_link_hash_undefweak
2248
+ && (eh == NULL
2249
+ || !UNDEFINED_WEAK_RESOLVED_TO_ZERO (info ,
2250
+ eh )))
2251
+ || (bfd_link_pie (info )
2252
+ && !SYMBOL_DEFINED_NON_SHARED_P (h )
2253
+ && h -> def_dynamic )
2254
+ || (no_copyreloc_p
2255
+ && h -> def_dynamic
2256
+ && !(h -> root .u .def .section -> flags & SEC_CODE ))))
2257
+ || bfd_link_dll (info )))
2258
+ {
2259
+ bfd_boolean fail = FALSE;
2260
+ if (SYMBOL_REFERENCES_LOCAL_P (info , h ))
2261
+ {
2262
+ /* Symbol is referenced locally. Make sure it is
2263
+ defined locally. */
2264
+ fail = !SYMBOL_DEFINED_NON_SHARED_P (h );
2265
+ }
2266
+ else if (bfd_link_pie (info ))
2267
+ {
2268
+ /* We can only use PC-relative relocations in PIE
2269
+ from non-code sections. */
2270
+ if (h -> type == STT_FUNC
2271
+ && (sec -> flags & SEC_CODE ) != 0 )
2272
+ fail = TRUE;
2273
+ }
2274
+ else if (no_copyreloc_p || bfd_link_dll (info ))
2275
+ {
2276
+ /* Symbol doesn't need copy reloc and isn't
2277
+ referenced locally. Don't allow PC-relative
2278
+ relocations against default and protected
2279
+ symbols since address of protected function
2280
+ and location of protected data may not be in
2281
+ the shared object. */
2282
+ fail = (ELF_ST_VISIBILITY (h -> other ) == STV_DEFAULT
2283
+ || ELF_ST_VISIBILITY (h -> other ) == STV_PROTECTED );
2284
+ }
2285
+
2286
+ if (fail )
2287
+ return elf_x86_64_need_pic (info , abfd , sec , h ,
2288
+ symtab_hdr , isym ,
2289
+ & x86_64_elf_howto_table [r_type ]);
2290
+ }
2291
+ }
2292
+
2226
2293
size_reloc = FALSE;
2227
2294
do_size :
2228
2295
if (NEED_DYNAMIC_RELOCATION_P (info , TRUE, h , sec , r_type ,
@@ -3065,56 +3132,14 @@ elf_x86_64_relocate_section (bfd *output_bfd,
3065
3132
case R_X86_64_PC16 :
3066
3133
case R_X86_64_PC32 :
3067
3134
case R_X86_64_PC32_BND :
3068
- /* Don't complain about -fPIC if the symbol is undefined when
3069
- building executable unless it is unresolved weak symbol,
3070
- references a dynamic definition in PIE or -z nocopyreloc
3071
- is used. */
3072
- if ((input_section -> flags & SEC_ALLOC ) != 0
3073
- && (input_section -> flags & SEC_READONLY ) != 0
3074
- && h != NULL
3075
- && ((bfd_link_executable (info )
3076
- && ((h -> root .type == bfd_link_hash_undefweak
3077
- && !resolved_to_zero )
3078
- || (bfd_link_pie (info )
3079
- && !h -> def_regular
3080
- && h -> def_dynamic )
3081
- || ((info -> nocopyreloc
3082
- || (eh -> def_protected
3083
- && elf_has_no_copy_on_protected (h -> root .u .def .section -> owner )))
3084
- && h -> def_dynamic
3085
- && !(h -> root .u .def .section -> flags & SEC_CODE ))))
3086
- || bfd_link_dll (info )))
3087
- {
3088
- bfd_boolean fail = FALSE;
3089
- if (SYMBOL_REFERENCES_LOCAL_P (info , h ))
3090
- {
3091
- /* Symbol is referenced locally. Make sure it is
3092
- defined locally. */
3093
- fail = !(h -> def_regular || ELF_COMMON_DEF_P (h ));
3094
- }
3095
- else if (!(bfd_link_pie (info )
3096
- && (h -> needs_copy || eh -> needs_copy )))
3097
- {
3098
- /* Symbol doesn't need copy reloc and isn't referenced
3099
- locally. Address of protected function may not be
3100
- reachable at run-time. */
3101
- fail = (ELF_ST_VISIBILITY (h -> other ) == STV_DEFAULT
3102
- || (ELF_ST_VISIBILITY (h -> other ) == STV_PROTECTED
3103
- && h -> type == STT_FUNC ));
3104
- }
3105
-
3106
- if (fail )
3107
- return elf_x86_64_need_pic (info , input_bfd , input_section ,
3108
- h , NULL , NULL , howto );
3109
- }
3110
3135
/* Since x86-64 has PC-relative PLT, we can use PLT in PIE
3111
3136
as function address. */
3112
- else if (h != NULL
3113
- && (input_section -> flags & SEC_CODE ) == 0
3114
- && bfd_link_pie (info )
3115
- && h -> type == STT_FUNC
3116
- && !h -> def_regular
3117
- && h -> def_dynamic )
3137
+ if (h != NULL
3138
+ && (input_section -> flags & SEC_CODE ) == 0
3139
+ && bfd_link_pie (info )
3140
+ && h -> type == STT_FUNC
3141
+ && !h -> def_regular
3142
+ && h -> def_dynamic )
3118
3143
goto use_plt ;
3119
3144
/* Fall through. */
3120
3145
@@ -4271,7 +4296,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
4271
4296
else if (bfd_link_pic (info )
4272
4297
&& SYMBOL_REFERENCES_LOCAL_P (info , h ))
4273
4298
{
4274
- if (!( h -> def_regular || ELF_COMMON_DEF_P ( h ) ))
4299
+ if (!SYMBOL_DEFINED_NON_SHARED_P ( h ))
4275
4300
return FALSE;
4276
4301
BFD_ASSERT ((h -> got .offset & 1 ) != 0 );
4277
4302
rela .r_info = htab -> r_info (0 , R_X86_64_RELATIVE );
0 commit comments