• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


コミットメタ情報

リビジョンc20c30f615756ddfccc4bb75c65ccfc1a399466e (tree)
日時2018-02-07 02:17:39
作者Eric Botcazou <ebotcazou@gcc....>
コミッターEric Botcazou

ログメッセージ

Fix PR ld/22263 on SPARC.

This is -fpie -pie generating dynamic relocations in the text section,
simply because no TLS transitions are applied in PIE mode. The meat
of the patch is to turn calls to bfd_link_pic (info) in TLS-related code
into !bfd_link_executable (info) and there are quite a lot of them...

bfd/
* elfxx-sparc.c (sparc_elf_tls_transition): Turn call to bfd_link_pic
into call to !bfd_link_executable and tidy up.
(_bfd_sparc_elf_check_relocs): Fix formatting and tidy up.
<R_SPARC_TLS_LE_HIX22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_IE_HI22>: Likewise.
<GOT relocations>: Remove useless code, tidy and merge blocks.
<R_SPARC_TLS_GD_CALL>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_WPLT30>: Tidy up.
(_bfd_sparc_elf_gc_mark_hook): Turn call to bfd_link_pic into call
to !bfd_link_executable.
(allocate_dynrelocs): Likewise.
(_bfd_sparc_elf_relocate_section): Fix formatting and tidy up.
<R_SPARC_TLS_GD_HI22>: Merge into...
<R_SPARC_TLS_GD_LO10>: ...this. Adjust 4th argument in call to
sparc_elf_tls_transition and remove redundant code.
<R_SPARC_TLS_LDM_HI22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_LDO_HIX22>: Likewise.
<R_SPARC_TLS_LE_HIX22>: Likewise. Tidy up.
<R_SPARC_TLS_LDM_CALL>: Likewise.
<R_SPARC_TLS_GD_CALL>: Likewise. Tidy up.
<R_SPARC_TLS_GD_ADD>: Likewise.
<R_SPARC_TLS_LDM_ADD>: Likewise.
<R_SPARC_TLS_LDO_ADD>: Likewise.
<R_SPARC_TLS_IE_LD>: Likewise.
ld/
* testsuite/ld-elf/tls.exp (AFLAGS_PIC): Define on SPARC.
(pr22263-1): Pass AFLAGS_PIC to the assembler.
* testsuite/ld-sparc/tlspie32.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie32.dd: Adjust to above.
* testsuite/ld-sparc/tlspie64.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie64.dd: Adjust to above.

変更サマリ

差分

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,34 @@
1+2018-02-06 Eric Botcazou <ebotcazou@adacore.com>
2+
3+ PR ld/22263
4+ * elfxx-sparc.c (sparc_elf_tls_transition): Turn call to bfd_link_pic
5+ into call to !bfd_link_executable and tidy up.
6+ (_bfd_sparc_elf_check_relocs): Fix formatting and tidy up.
7+ <R_SPARC_TLS_LE_HIX22>: Turn call to bfd_link_pic into call to
8+ !bfd_link_executable.
9+ <R_SPARC_TLS_IE_HI22>: Likewise.
10+ <GOT relocations>: Remove useless code, tidy and merge related blocks.
11+ <R_SPARC_TLS_GD_CALL>: Turn call to bfd_link_pic into call to
12+ !bfd_link_executable.
13+ <R_SPARC_WPLT30>: Tidy up.
14+ (_bfd_sparc_elf_gc_mark_hook): Turn call to bfd_link_pic into call to
15+ !bfd_link_executable.
16+ (allocate_dynrelocs): Likewise.
17+ (_bfd_sparc_elf_relocate_section): Fix formatting and tidy up.
18+ <R_SPARC_TLS_GD_HI22>: Merge into...
19+ <R_SPARC_TLS_GD_LO10>: ...this. Adjust 4th argument in call to
20+ sparc_elf_tls_transition and remove redundant code.
21+ <R_SPARC_TLS_LDM_HI22>: Turn call to bfd_link_pic into call to
22+ !bfd_link_executable.
23+ <R_SPARC_TLS_LDO_HIX22>: Likewise.
24+ <R_SPARC_TLS_LE_HIX22>: Likewise. Tidy up.
25+ <R_SPARC_TLS_LDM_CALL>: Likewise.
26+ <R_SPARC_TLS_GD_CALL>: Likewise. Tidy up.
27+ <R_SPARC_TLS_GD_ADD>: Likewise.
28+ <R_SPARC_TLS_LDM_ADD>: Likewise.
29+ <R_SPARC_TLS_LDO_ADD>: Likewise.
30+ <R_SPARC_TLS_IE_LD>: Likewise.
31+
132 2018-02-06 Miloš Stojanović <milos.stojanovic@rt-rk.com>
233
334 PR 22789
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -1331,33 +1331,25 @@ sparc_elf_tls_transition (struct bfd_link_info *info, bfd *abfd,
13311331 if (! ABI_64_P (abfd)
13321332 && r_type == R_SPARC_TLS_GD_HI22
13331333 && ! _bfd_sparc_elf_tdata (abfd)->has_tlsgd)
1334- r_type = R_SPARC_REV32;
1334+ return R_SPARC_REV32;
13351335
1336- if (bfd_link_pic (info))
1336+ if (!bfd_link_executable (info))
13371337 return r_type;
13381338
13391339 switch (r_type)
13401340 {
13411341 case R_SPARC_TLS_GD_HI22:
1342- if (is_local)
1343- return R_SPARC_TLS_LE_HIX22;
1344- return R_SPARC_TLS_IE_HI22;
1342+ return is_local ? R_SPARC_TLS_LE_HIX22 : R_SPARC_TLS_IE_HI22;
13451343 case R_SPARC_TLS_GD_LO10:
1346- if (is_local)
1347- return R_SPARC_TLS_LE_LOX10;
1348- return R_SPARC_TLS_IE_LO10;
1349- case R_SPARC_TLS_IE_HI22:
1350- if (is_local)
1351- return R_SPARC_TLS_LE_HIX22;
1352- return r_type;
1353- case R_SPARC_TLS_IE_LO10:
1354- if (is_local)
1355- return R_SPARC_TLS_LE_LOX10;
1356- return r_type;
1344+ return is_local ? R_SPARC_TLS_LE_LOX10 : R_SPARC_TLS_IE_LO10;
13571345 case R_SPARC_TLS_LDM_HI22:
13581346 return R_SPARC_TLS_LE_HIX22;
13591347 case R_SPARC_TLS_LDM_LO10:
13601348 return R_SPARC_TLS_LE_LOX10;
1349+ case R_SPARC_TLS_IE_HI22:
1350+ return is_local ? R_SPARC_TLS_LE_HIX22 : r_type;
1351+ case R_SPARC_TLS_IE_LO10:
1352+ return is_local ? R_SPARC_TLS_LE_LOX10 : r_type;
13611353 }
13621354
13631355 return r_type;
@@ -1425,16 +1417,14 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
14251417 if (r_symndx < symtab_hdr->sh_info)
14261418 {
14271419 /* A local symbol. */
1428- isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1429- abfd, r_symndx);
1420+ isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
14301421 if (isym == NULL)
14311422 return FALSE;
14321423
14331424 /* Check relocation against local STT_GNU_IFUNC symbol. */
14341425 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
14351426 {
1436- h = elf_sparc_get_local_sym_hash (htab, abfd, rel,
1437- TRUE);
1427+ h = elf_sparc_get_local_sym_hash (htab, abfd, rel, TRUE);
14381428 if (h == NULL)
14391429 return FALSE;
14401430
@@ -1456,13 +1446,10 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
14561446 h = (struct elf_link_hash_entry *) h->root.u.i.link;
14571447 }
14581448
1459- if (h && h->type == STT_GNU_IFUNC)
1449+ if (h && h->type == STT_GNU_IFUNC && h->def_regular)
14601450 {
1461- if (h->def_regular)
1462- {
1463- h->ref_regular = 1;
1464- h->plt.refcount += 1;
1465- }
1451+ h->ref_regular = 1;
1452+ h->plt.refcount += 1;
14661453 }
14671454
14681455 /* Compatibility with old R_SPARC_REV32 reloc conflicting
@@ -1505,13 +1492,13 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
15051492
15061493 case R_SPARC_TLS_LE_HIX22:
15071494 case R_SPARC_TLS_LE_LOX10:
1508- if (bfd_link_pic (info))
1495+ if (!bfd_link_executable (info))
15091496 goto r_sparc_plt32;
15101497 break;
15111498
15121499 case R_SPARC_TLS_IE_HI22:
15131500 case R_SPARC_TLS_IE_LO10:
1514- if (bfd_link_pic (info))
1501+ if (!bfd_link_executable (info))
15151502 info->flags |= DF_STATIC_TLS;
15161503 /* Fall through */
15171504
@@ -1530,14 +1517,6 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
15301517
15311518 switch (r_type)
15321519 {
1533- default:
1534- case R_SPARC_GOT10:
1535- case R_SPARC_GOT13:
1536- case R_SPARC_GOT22:
1537- case R_SPARC_GOTDATA_OP_HIX22:
1538- case R_SPARC_GOTDATA_OP_LOX10:
1539- tls_type = GOT_NORMAL;
1540- break;
15411520 case R_SPARC_TLS_GD_HI22:
15421521 case R_SPARC_TLS_GD_LO10:
15431522 tls_type = GOT_TLS_GD;
@@ -1546,6 +1525,9 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
15461525 case R_SPARC_TLS_IE_LO10:
15471526 tls_type = GOT_TLS_IE;
15481527 break;
1528+ default:
1529+ tls_type = GOT_NORMAL;
1530+ break;
15491531 }
15501532
15511533 if (h != NULL)
@@ -1573,26 +1555,23 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
15731555 _bfd_sparc_elf_local_got_tls_type (abfd)
15741556 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
15751557 }
1576- switch (r_type)
1577- {
1578- case R_SPARC_GOTDATA_OP_HIX22:
1579- case R_SPARC_GOTDATA_OP_LOX10:
1580- break;
15811558
1582- default:
1583- local_got_refcounts[r_symndx] += 1;
1584- break;
1585- }
1559+ if (r_type != R_SPARC_GOTDATA_OP_HIX22
1560+ && r_type != R_SPARC_GOTDATA_OP_LOX10)
1561+ local_got_refcounts[r_symndx] += 1;
1562+
15861563 old_tls_type = _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx];
15871564 }
15881565
1589- /* If a TLS symbol is accessed using IE at least once,
1590- there is no point to use dynamic model for it. */
1591- if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1592- && (old_tls_type != GOT_TLS_GD
1593- || tls_type != GOT_TLS_IE))
1566+ /* If a TLS symbol is accessed using IE at least once, there is no point
1567+ in using the dynamic model for it. */
1568+ if (old_tls_type != tls_type)
15941569 {
1595- if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
1570+ if (old_tls_type == GOT_UNKNOWN)
1571+ ;
1572+ else if (old_tls_type == GOT_TLS_GD && tls_type == GOT_TLS_IE)
1573+ ;
1574+ else if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
15961575 tls_type = old_tls_type;
15971576 else
15981577 {
@@ -1602,10 +1581,7 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
16021581 abfd, h ? h->root.root.string : "<local>");
16031582 return FALSE;
16041583 }
1605- }
16061584
1607- if (old_tls_type != tls_type)
1608- {
16091585 if (h != NULL)
16101586 _bfd_sparc_elf_hash_entry (h)->tls_type = tls_type;
16111587 else
@@ -1613,11 +1589,9 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
16131589 }
16141590 }
16151591
1616- if (htab->elf.sgot == NULL)
1617- {
1618- if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
1619- return FALSE;
1620- }
1592+ if (!htab->elf.sgot
1593+ && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
1594+ return FALSE;
16211595
16221596 if (eh != NULL)
16231597 eh->has_got_reloc = 1;
@@ -1625,28 +1599,25 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
16251599
16261600 case R_SPARC_TLS_GD_CALL:
16271601 case R_SPARC_TLS_LDM_CALL:
1628- if (bfd_link_pic (info))
1629- {
1630- /* These are basically R_SPARC_TLS_WPLT30 relocs against
1631- __tls_get_addr. */
1632- h = (struct elf_link_hash_entry *)
1633- bfd_link_hash_lookup (info->hash, "__tls_get_addr", TRUE,
1634- FALSE, TRUE);
1635- }
1636- else
1602+ if (bfd_link_executable (info))
16371603 break;
1604+
1605+ /* Essentially R_SPARC_WPLT30 relocs against __tls_get_addr. */
1606+ h = (struct elf_link_hash_entry *)
1607+ bfd_link_hash_lookup (info->hash, "__tls_get_addr", TRUE,
1608+ FALSE, TRUE);
16381609 /* Fall through */
16391610
1640- case R_SPARC_PLT32:
16411611 case R_SPARC_WPLT30:
1612+ case R_SPARC_PLT32:
1613+ case R_SPARC_PLT64:
16421614 case R_SPARC_HIPLT22:
16431615 case R_SPARC_LOPLT10:
16441616 case R_SPARC_PCPLT32:
16451617 case R_SPARC_PCPLT22:
16461618 case R_SPARC_PCPLT10:
1647- case R_SPARC_PLT64:
1648- /* This symbol requires a procedure linkage table entry. We
1649- actually build the entry in adjust_dynamic_symbol,
1619+ /* This symbol requires a procedure linkage table entry.
1620+ We actually build the entry in adjust_dynamic_symbol,
16501621 because this might be a case of linking PIC code without
16511622 linking in any dynamic objects, in which case we don't
16521623 need to generate a procedure linkage table after all. */
@@ -1659,7 +1630,7 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
16591630 reloc for a local symbol if you assemble a call from
16601631 one section to another when using -K pic. We treat
16611632 it as WDISP30. */
1662- if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32)
1633+ if (r_type == R_SPARC_PLT32)
16631634 goto r_sparc_plt32;
16641635 break;
16651636 }
@@ -1675,14 +1646,9 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
16751646
16761647 h->needs_plt = 1;
16771648
1678- {
1679- int this_r_type;
1649+ if (r_type == R_SPARC_PLT32 || r_type == R_SPARC_PLT64)
1650+ goto r_sparc_plt32;
16801651
1681- this_r_type = SPARC_ELF_R_TYPE (rel->r_info);
1682- if (this_r_type == R_SPARC_PLT32
1683- || this_r_type == R_SPARC_PLT64)
1684- goto r_sparc_plt32;
1685- }
16861652 h->plt.refcount += 1;
16871653
16881654 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
@@ -1886,9 +1852,7 @@ _bfd_sparc_elf_gc_mark_hook (asection *sec,
18861852 return NULL;
18871853 }
18881854
1889- /* FIXME: The test here, in check_relocs and in relocate_section
1890- dealing with TLS optimization, ought to be !bfd_link_executable (info). */
1891- if (bfd_link_pic (info))
1855+ if (!bfd_link_executable (info))
18921856 {
18931857 switch (SPARC_ELF_R_TYPE (rel->r_info))
18941858 {
@@ -2227,7 +2191,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
22272191 /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary,
22282192 make it a R_SPARC_TLS_LE_{HI22,LO10} requiring no TLS entry. */
22292193 if (h->got.refcount > 0
2230- && !bfd_link_pic (info)
2194+ && bfd_link_executable (info)
22312195 && h->dynindx == -1
22322196 && _bfd_sparc_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
22332197 h->got.offset = (bfd_vma) -1;
@@ -2963,8 +2927,8 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
29632927 bfd_set_error (bfd_error_bad_value);
29642928 return FALSE;
29652929 }
2966- howto = _bfd_sparc_elf_howto_table + r_type;
29672930
2931+ howto = _bfd_sparc_elf_howto_table + r_type;
29682932 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
29692933 h = NULL;
29702934 sym = NULL;
@@ -3131,8 +3095,7 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
31313095 }
31323096
31333097 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
3134- resolved_to_zero = (eh != NULL
3135- && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh));
3098+ resolved_to_zero = eh && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
31363099
31373100 switch (r_type)
31383101 {
@@ -3378,8 +3341,7 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
33783341 case R_SPARC_H34:
33793342 case R_SPARC_UA64:
33803343 r_sparc_plt32:
3381- if ((input_section->flags & SEC_ALLOC) == 0
3382- || is_vxworks_tls)
3344+ if ((input_section->flags & SEC_ALLOC) == 0 || is_vxworks_tls)
33833345 break;
33843346
33853347 /* Copy dynamic function pointer relocations. Don't generate
@@ -3551,40 +3513,19 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
35513513 break;
35523514
35533515 case R_SPARC_TLS_GD_HI22:
3554- if (! ABI_64_P (input_bfd)
3555- && ! _bfd_sparc_elf_tdata (input_bfd)->has_tlsgd)
3556- {
3557- /* R_SPARC_REV32 used the same reloc number as
3558- R_SPARC_TLS_GD_HI22. */
3559- r_type = R_SPARC_REV32;
3560- break;
3561- }
3562- /* Fall through */
3563-
35643516 case R_SPARC_TLS_GD_LO10:
35653517 case R_SPARC_TLS_IE_HI22:
35663518 case R_SPARC_TLS_IE_LO10:
3567- r_type = sparc_elf_tls_transition (info, input_bfd, r_type, h == NULL);
3568- tls_type = GOT_UNKNOWN;
3569- if (h == NULL && local_got_offsets)
3519+ r_type = sparc_elf_tls_transition (info, input_bfd, r_type,
3520+ h == NULL || h->dynindx == -1);
3521+ if (r_type == R_SPARC_REV32)
3522+ break;
3523+ if (h != NULL)
3524+ tls_type = _bfd_sparc_elf_hash_entry (h)->tls_type;
3525+ else if (local_got_offsets)
35703526 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3571- else if (h != NULL)
3572- {
3573- tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
3574- if (!bfd_link_pic (info)
3575- && h->dynindx == -1
3576- && tls_type == GOT_TLS_IE)
3577- switch (SPARC_ELF_R_TYPE (rel->r_info))
3578- {
3579- case R_SPARC_TLS_GD_HI22:
3580- case R_SPARC_TLS_IE_HI22:
3581- r_type = R_SPARC_TLS_LE_HIX22;
3582- break;
3583- default:
3584- r_type = R_SPARC_TLS_LE_LOX10;
3585- break;
3586- }
3587- }
3527+ else
3528+ tls_type = GOT_UNKNOWN;
35883529 if (tls_type == GOT_TLS_IE)
35893530 switch (r_type)
35903531 {
@@ -3695,7 +3636,8 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
36953636
36963637 case R_SPARC_TLS_LDM_HI22:
36973638 case R_SPARC_TLS_LDM_LO10:
3698- if (! bfd_link_pic (info))
3639+ /* LD -> LE */
3640+ if (bfd_link_executable (info))
36993641 {
37003642 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
37013643 continue;
@@ -3706,43 +3648,42 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
37063648
37073649 case R_SPARC_TLS_LDO_HIX22:
37083650 case R_SPARC_TLS_LDO_LOX10:
3709- if (bfd_link_pic (info))
3651+ /* LD -> LE */
3652+ if (bfd_link_executable (info))
3653+ {
3654+ if (r_type == R_SPARC_TLS_LDO_HIX22)
3655+ r_type = R_SPARC_TLS_LE_HIX22;
3656+ else
3657+ r_type = R_SPARC_TLS_LE_LOX10;
3658+ }
3659+ else
37103660 {
37113661 relocation -= dtpoff_base (info);
37123662 break;
37133663 }
3714-
3715- r_type = (r_type == R_SPARC_TLS_LDO_HIX22
3716- ? R_SPARC_TLS_LE_HIX22 : R_SPARC_TLS_LE_LOX10);
37173664 /* Fall through. */
37183665
37193666 case R_SPARC_TLS_LE_HIX22:
37203667 case R_SPARC_TLS_LE_LOX10:
3721- if (bfd_link_pic (info))
3668+ if (!bfd_link_executable (info))
37223669 {
37233670 Elf_Internal_Rela outrel;
3724- bfd_boolean skip;
3725-
3726- BFD_ASSERT (sreloc != NULL);
3727- skip = FALSE;
3728- outrel.r_offset =
3729- _bfd_elf_section_offset (output_bfd, info, input_section,
3730- rel->r_offset);
3731- if (outrel.r_offset == (bfd_vma) -1)
3732- skip = TRUE;
3733- else if (outrel.r_offset == (bfd_vma) -2)
3734- skip = TRUE;
3735- outrel.r_offset += (input_section->output_section->vma
3736- + input_section->output_offset);
3737- if (skip)
3671+ bfd_vma offset
3672+ = _bfd_elf_section_offset (output_bfd, info, input_section,
3673+ rel->r_offset);
3674+ if (offset == (bfd_vma) -1 || offset == (bfd_vma) -2)
37383675 memset (&outrel, 0, sizeof outrel);
37393676 else
37403677 {
3678+ outrel.r_offset = offset
3679+ + input_section->output_section->vma
3680+ + input_section->output_offset;
37413681 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, r_type);
3742- outrel.r_addend = relocation - dtpoff_base (info)
3743- + rel->r_addend;
3682+ outrel.r_addend
3683+ = relocation - dtpoff_base (info) + rel->r_addend;
37443684 }
37453685
3686+ BFD_ASSERT (sreloc != NULL);
37463687 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
37473688 continue;
37483689 }
@@ -3750,7 +3691,8 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
37503691 break;
37513692
37523693 case R_SPARC_TLS_LDM_CALL:
3753- if (! bfd_link_pic (info))
3694+ /* LD -> LE */
3695+ if (bfd_link_executable (info))
37543696 {
37553697 /* mov %g0, %o0 */
37563698 bfd_put_32 (output_bfd, 0x90100000, contents + rel->r_offset);
@@ -3759,20 +3701,22 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
37593701 /* Fall through */
37603702
37613703 case R_SPARC_TLS_GD_CALL:
3762- tls_type = GOT_UNKNOWN;
3763- if (h == NULL && local_got_offsets)
3704+ if (h != NULL)
3705+ tls_type = _bfd_sparc_elf_hash_entry (h)->tls_type;
3706+ else if (local_got_offsets)
37643707 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3765- else if (h != NULL)
3766- tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
3767- if (! bfd_link_pic (info)
3708+ else
3709+ tls_type = GOT_UNKNOWN;
3710+ /* GD -> IE or LE */
3711+ if (bfd_link_executable (info)
37683712 || (r_type == R_SPARC_TLS_GD_CALL && tls_type == GOT_TLS_IE))
37693713 {
37703714 Elf_Internal_Rela *rel2;
37713715 bfd_vma insn;
37723716
3773- if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
3717+ /* GD -> LE */
3718+ if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
37743719 {
3775- /* GD -> LE */
37763720 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
37773721 continue;
37783722 }
@@ -3835,12 +3779,14 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
38353779 goto r_sparc_wplt30;
38363780
38373781 case R_SPARC_TLS_GD_ADD:
3838- tls_type = GOT_UNKNOWN;
3839- if (h == NULL && local_got_offsets)
3782+ if (h != NULL)
3783+ tls_type = _bfd_sparc_elf_hash_entry (h)->tls_type;
3784+ else if (local_got_offsets)
38403785 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3841- else if (h != NULL)
3842- tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
3843- if (! bfd_link_pic (info) || tls_type == GOT_TLS_IE)
3786+ else
3787+ tls_type = GOT_UNKNOWN;
3788+ /* GD -> IE or LE */
3789+ if (bfd_link_executable (info) || tls_type == GOT_TLS_IE)
38443790 {
38453791 /* add %reg1, %reg2, %reg3, %tgd_add(foo)
38463792 changed into IE:
@@ -3848,21 +3794,23 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
38483794 or LE:
38493795 add %g7, %reg2, %reg3. */
38503796 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3851- if ((h != NULL && h->dynindx != -1) || bfd_link_pic (info))
3852- relocation = insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000);
3853- else
3797+ if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
38543798 relocation = (insn & ~0x7c000) | 0x1c000;
3799+ else
3800+ relocation = insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000);
38553801 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
38563802 }
38573803 continue;
38583804
38593805 case R_SPARC_TLS_LDM_ADD:
3860- if (! bfd_link_pic (info))
3806+ /* LD -> LE */
3807+ if (bfd_link_executable (info))
38613808 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
38623809 continue;
38633810
38643811 case R_SPARC_TLS_LDO_ADD:
3865- if (! bfd_link_pic (info))
3812+ /* LD -> LE */
3813+ if (bfd_link_executable (info))
38663814 {
38673815 /* Change rs1 into %g7. */
38683816 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
@@ -3873,7 +3821,8 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
38733821
38743822 case R_SPARC_TLS_IE_LD:
38753823 case R_SPARC_TLS_IE_LDX:
3876- if (! bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
3824+ /* IE -> LE */
3825+ if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
38773826 {
38783827 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
38793828 int rs2 = insn & 0x1f;
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
1+2018-02-06 Eric Botcazou <ebotcazou@adacore.com>
2+
3+ * gcc-plugin.m4 (GCC_ENABLE_PLUGINS): Remove -q option passed to grep.
4+
15 2018-01-10 Nick Clifton <nickc@redhat.com>
26
37 * Sync with GCC sources:
--- a/config/gcc-plugin.m4
+++ b/config/gcc-plugin.m4
@@ -60,14 +60,14 @@ AC_DEFUN([GCC_ENABLE_PLUGINS],
6060 if test "x$export_sym_check" != x; then
6161 echo "int main() {return 0;} int foobar() {return 0;}" > conftest.c
6262 ${CC} ${CFLAGS} ${LDFLAGS} conftest.c -o conftest$ac_exeext > /dev/null 2>&1
63- if $export_sym_check conftest$ac_exeext | grep -q foobar > /dev/null; then
63+ if $export_sym_check conftest$ac_exeext | grep foobar > /dev/null; then
6464 : # No need to use a flag
6565 AC_MSG_RESULT([yes])
6666 else
6767 AC_MSG_RESULT([yes])
6868 AC_MSG_CHECKING([for -rdynamic])
6969 ${CC} ${CFLAGS} ${LDFLAGS} -rdynamic conftest.c -o conftest$ac_exeext > /dev/null 2>&1
70- if $export_sym_check conftest$ac_exeext | grep -q foobar > /dev/null; then
70+ if $export_sym_check conftest$ac_exeext | grep foobar > /dev/null; then
7171 plugin_rdynamic=yes
7272 pluginlibs="-rdynamic"
7373 else
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
1+2018-02-06 Eric Botcazou <ebotcazou@adacore.com>
2+
3+ * testsuite/ld-elf/tls.exp (AFLAGS_PIC): Define on SPARC.
4+ (pr22263-1): Pass AFLAGS_PIC to the assembler.
5+ * testsuite/ld-sparc/tlspie32.s: Add test for other 3 transitions.
6+ * testsuite/ld-sparc/tlspie32.dd: Adjust to above.
7+ * testsuite/ld-sparc/tlspie64.s: Add test for other 3 transitions.
8+ * testsuite/ld-sparc/tlspie64.dd: Adjust to above.
9+
110 2018-02-05 Renlin Li <renlin.li@arm.com>
211
312 PR ld/22764
--- a/ld/testsuite/ld-elf/tls.exp
+++ b/ld/testsuite/ld-elf/tls.exp
@@ -37,12 +37,18 @@ if { [which $CC] == 0 } {
3737 return
3838 }
3939
40+# This target requires extra GAS options when building PIC/PIE code.
41+set AFLAGS_PIC ""
42+if [istarget "sparc*-*-*"] {
43+ append AFLAGS_PIC " -K PIC"
44+}
45+
4046 run_ld_link_tests [list \
4147 [list \
4248 "Build pr22263-1" \
4349 "-pie -e _start -z text" \
4450 "" \
45- "" \
51+ "$AFLAGS_PIC" \
4652 { pr22263-1a.c pr22263-1b.c } \
4753 {{readelf -r pr22263-1.rd}} \
4854 "pr22263-1" \
--- a/ld/testsuite/ld-sparc/tlspie32.dd
+++ b/ld/testsuite/ld-sparc/tlspie32.dd
@@ -10,9 +10,56 @@
1010
1111 Disassembly of section .text:
1212
13-0[0-9a-f]+ <get_gdp>:
13+0[0-9a-f]+ <foo-0x8>:
14+ +[0-9a-f]+: 81 c3 e0 08 retl
15+ +[0-9a-f]+: ae 03 c0 17 add %o7, %l7, %l7
16+
17+0[0-9a-f]+ <foo>:
18+ +[0-9a-f]+: 9d e3 bf 98 save %sp, -104, %sp
19+ +[0-9a-f]+: 2f 00 00 40 sethi %hi\(0x10000\), %l7
20+ +[0-9a-f]+: 7f ff ff fc call [0-9a-f]+ <.*>
21+ +[0-9a-f]+: ae 05 e1 60 add %l7, 0x160, %l7 ! 10160 <.*>
22+ +[0-9a-f]+: 01 00 00 00 nop
23+ +[0-9a-f]+: 01 00 00 00 nop
24+ +[0-9a-f]+: 01 00 00 00 nop
25+ +[0-9a-f]+: 01 00 00 00 nop
26+ +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
27+ +[0-9a-f]+: 82 00 60 04 add %g1, 4, %g1 ! 4 <.*>
28+ +[0-9a-f]+: d0 05 c0 01 ld \[ %l7 \+ %g1 ], %o0
29+ +[0-9a-f]+: 01 00 00 00 nop
30+ +[0-9a-f]+: 90 01 c0 08 add %g7, %o0, %o0
31+ +[0-9a-f]+: 01 00 00 00 nop
32+ +[0-9a-f]+: 01 00 00 00 nop
33+ +[0-9a-f]+: 01 00 00 00 nop
34+ +[0-9a-f]+: 01 00 00 00 nop
1435 +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
15- +[0-9a-f]+: 82 00 60 04 add %g1, 4, %g1 ! 4 <tls_gd\+0x4>
16- +[0-9a-f]+: 90 05 c0 01 add %l7, %g1, %o0
17- +[0-9a-f]+: 40 00 40 43 call [0-9a-f]+ <__tls_get_addr@plt>
36+ +[0-9a-f]+: 82 18 7f f4 xor %g1, -12, %g1
37+ +[0-9a-f]+: 90 01 c0 01 add %g7, %g1, %o0
38+ +[0-9a-f]+: 01 00 00 00 nop
39+ +[0-9a-f]+: 01 00 00 00 nop
40+ +[0-9a-f]+: 01 00 00 00 nop
41+ +[0-9a-f]+: 01 00 00 00 nop
42+ +[0-9a-f]+: 01 00 00 00 nop
43+ +[0-9a-f]+: 01 00 00 00 nop
44+ +[0-9a-f]+: 01 00 00 00 nop
45+ +[0-9a-f]+: 01 00 00 00 nop
46+ +[0-9a-f]+: 01 00 00 00 nop
47+ +[0-9a-f]+: 90 10 00 00 mov %g0, %o0
48+ +[0-9a-f]+: 01 00 00 00 nop
49+ +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
50+ +[0-9a-f]+: 82 18 7f f8 xor %g1, -8, %g1
51+ +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1
52+ +[0-9a-f]+: 01 00 00 00 nop
53+ +[0-9a-f]+: 01 00 00 00 nop
54+ +[0-9a-f]+: 01 00 00 00 nop
55+ +[0-9a-f]+: 01 00 00 00 nop
56+ +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
57+ +[0-9a-f]+: 82 18 7f fc xor %g1, -4, %g1
58+ +[0-9a-f]+: 01 00 00 00 nop
59+ +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1
60+ +[0-9a-f]+: 01 00 00 00 nop
61+ +[0-9a-f]+: 01 00 00 00 nop
62+ +[0-9a-f]+: 01 00 00 00 nop
1863 +[0-9a-f]+: 01 00 00 00 nop
64+ +[0-9a-f]+: 81 c7 e0 08 ret
65+ +[0-9a-f]+: 81 e8 00 00 restore
--- a/ld/testsuite/ld-sparc/tlspie32.s
+++ b/ld/testsuite/ld-sparc/tlspie32.s
@@ -1,20 +1,70 @@
1- .section ".text"
2- .global tls_gd
31 .section .tbss,"awT",@nobits
2+ .global tls_gd
43 .align 4
54 .type tls_gd, #object
65 .size tls_gd, 4
76 tls_gd:
87 .skip 4
8+ .global tls_ld
9+ .align 4
10+ .type tls_ld, #object
11+ .size tls_ld, 4
12+tls_ld:
13+ .skip 4
14+ .global tls_ie
15+ .align 4
16+ .type tls_ie, #object
17+ .size tls_ie, 4
18+tls_ie:
19+ .skip 4
920 .section ".text"
21+.LLGETPC0:
22+ retl
23+ add %o7, %l7, %l7
1024 .align 4
11- .global get_gdp
12- .type get_gdp, #function
25+ .global foo
26+ .type foo, #function
1327 .proc 0104
14-get_gdp:
28+foo:
29+ save %sp, -104, %sp
30+ sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
31+ call .LLGETPC0
32+ add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
33+ nop;nop;nop;nop
34+
35+ /* GD -> IE with global variable not defined in executable */
36+ sethi %tgd_hi22(sG1), %g1
37+ add %g1, %tgd_lo10(sG1), %g1
38+ add %l7, %g1, %o0, %tgd_add(sG1)
39+ call __tls_get_addr, %tgd_call(sG1)
40+ nop
41+ nop;nop;nop;nop
42+
43+ /* GD -> LE with global variable defined in executable */
1544 sethi %tgd_hi22(tls_gd), %g1
1645 add %g1, %tgd_lo10(tls_gd), %g1
1746 add %l7, %g1, %o0, %tgd_add(tls_gd)
1847 call __tls_get_addr, %tgd_call(tls_gd)
1948 nop
20- .size get_gdp, .-get_gdp
49+ nop;nop;nop;nop
50+
51+ /* LD -> LE with global variable defined in executable */
52+ sethi %tldm_hi22(tls_ld), %g1
53+ add %g1, %tldm_lo10(tls_ld), %g1
54+ add %l7, %g1, %o0, %tldm_add(tls_ld)
55+ call __tls_get_addr, %tldm_call(tls_ld)
56+ nop
57+ sethi %tldo_hix22(tls_ld), %g1
58+ xor %g1, %tldo_lox10(tls_ld), %g1
59+ add %o0, %g1, %g1, %tldo_add(tls_ld)
60+ nop;nop;nop;nop
61+
62+ /* IE -> LE with global variable defined in executable */
63+ sethi %tie_hi22(tls_ie), %g1
64+ add %g1, %tie_lo10(tls_ie), %g1
65+ ld [%l7 + %g1], %g1, %tie_ld(tls_ie)
66+ add %g7, %g1, %g1, %tie_add(tls_ie)
67+ nop;nop;nop;nop
68+
69+ ret
70+ restore
--- a/ld/testsuite/ld-sparc/tlspie64.dd
+++ b/ld/testsuite/ld-sparc/tlspie64.dd
@@ -10,9 +10,56 @@
1010
1111 Disassembly of section .text:
1212
13-0[0-9a-f]+ <get_gdp>:
13+0[0-9a-f]+ <foo-0x8>:
14+ +[0-9a-f]+: 81 c3 e0 08 retl
15+ +[0-9a-f]+: ae 03 c0 17 add %o7, %l7, %l7
16+
17+0[0-9a-f]+ <foo>:
18+ +[0-9a-f]+: 9d e3 bf 60 save %sp, -160, %sp
19+ +[0-9a-f]+: 2f 00 04 00 sethi %hi\(0x100000\), %l7
20+ +[0-9a-f]+: 7f ff ff fc call [0-9a-f]+ <.*>
21+ +[0-9a-f]+: ae 05 e2 08 add %l7, 0x208, %l7 ! 100208 <.*>
22+ +[0-9a-f]+: 01 00 00 00 nop
23+ +[0-9a-f]+: 01 00 00 00 nop
24+ +[0-9a-f]+: 01 00 00 00 nop
25+ +[0-9a-f]+: 01 00 00 00 nop
26+ +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
27+ +[0-9a-f]+: 82 00 60 08 add %g1, 8, %g1 ! 8 <.*>
28+ +[0-9a-f]+: d0 5d c0 01 ldx \[ %l7 \+ %g1 ], %o0
29+ +[0-9a-f]+: 01 00 00 00 nop
30+ +[0-9a-f]+: 90 01 c0 08 add %g7, %o0, %o0
31+ +[0-9a-f]+: 01 00 00 00 nop
32+ +[0-9a-f]+: 01 00 00 00 nop
33+ +[0-9a-f]+: 01 00 00 00 nop
34+ +[0-9a-f]+: 01 00 00 00 nop
1435 +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
15- +[0-9a-f]+: 82 00 60 08 add %g1, 8, %g1 ! 8 <tls_gd\+0x8>
16- +[0-9a-f]+: 90 05 c0 01 add %l7, %g1, %o0
17- +[0-9a-f]+: 40 04 00 bb call [0-9a-f]+ <__tls_get_addr@plt>
36+ +[0-9a-f]+: 82 18 7f f4 xor %g1, -12, %g1
37+ +[0-9a-f]+: 90 01 c0 01 add %g7, %g1, %o0
38+ +[0-9a-f]+: 01 00 00 00 nop
39+ +[0-9a-f]+: 01 00 00 00 nop
40+ +[0-9a-f]+: 01 00 00 00 nop
41+ +[0-9a-f]+: 01 00 00 00 nop
42+ +[0-9a-f]+: 01 00 00 00 nop
43+ +[0-9a-f]+: 01 00 00 00 nop
44+ +[0-9a-f]+: 01 00 00 00 nop
45+ +[0-9a-f]+: 01 00 00 00 nop
46+ +[0-9a-f]+: 01 00 00 00 nop
47+ +[0-9a-f]+: 90 10 00 00 mov %g0, %o0
48+ +[0-9a-f]+: 01 00 00 00 nop
49+ +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
50+ +[0-9a-f]+: 82 18 7f f8 xor %g1, -8, %g1
51+ +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1
52+ +[0-9a-f]+: 01 00 00 00 nop
53+ +[0-9a-f]+: 01 00 00 00 nop
54+ +[0-9a-f]+: 01 00 00 00 nop
55+ +[0-9a-f]+: 01 00 00 00 nop
56+ +[0-9a-f]+: 03 00 00 00 sethi %hi\(0\), %g1
57+ +[0-9a-f]+: 82 18 7f fc xor %g1, -4, %g1
58+ +[0-9a-f]+: 01 00 00 00 nop
59+ +[0-9a-f]+: 82 01 c0 01 add %g7, %g1, %g1
60+ +[0-9a-f]+: 01 00 00 00 nop
61+ +[0-9a-f]+: 01 00 00 00 nop
62+ +[0-9a-f]+: 01 00 00 00 nop
1863 +[0-9a-f]+: 01 00 00 00 nop
64+ +[0-9a-f]+: 81 c7 e0 08 ret
65+ +[0-9a-f]+: 81 e8 00 00 restore
--- a/ld/testsuite/ld-sparc/tlspie64.s
+++ b/ld/testsuite/ld-sparc/tlspie64.s
@@ -1,20 +1,70 @@
1- .section ".text"
2- .global tls_gd
31 .section .tbss,"awT",@nobits
2+ .global tls_gd
43 .align 4
54 .type tls_gd, #object
65 .size tls_gd, 4
76 tls_gd:
87 .skip 4
8+ .global tls_ld
9+ .align 4
10+ .type tls_ld, #object
11+ .size tls_ld, 4
12+tls_ld:
13+ .skip 4
14+ .global tls_ie
15+ .align 4
16+ .type tls_ie, #object
17+ .size tls_ie, 4
18+tls_ie:
19+ .skip 4
920 .section ".text"
21+.LLGETPC0:
22+ retl
23+ add %o7, %l7, %l7
1024 .align 4
11- .global get_gdp
12- .type get_gdp, #function
25+ .global foo
26+ .type foo, #function
1327 .proc 0104
14-get_gdp:
28+foo:
29+ save %sp, -160, %sp
30+ sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
31+ call .LLGETPC0
32+ add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
33+ nop;nop;nop;nop
34+
35+ /* GD -> IE with global variable not defined in executable */
36+ sethi %tgd_hi22(sG1), %g1
37+ add %g1, %tgd_lo10(sG1), %g1
38+ add %l7, %g1, %o0, %tgd_add(sG1)
39+ call __tls_get_addr, %tgd_call(sG1)
40+ nop
41+ nop;nop;nop;nop
42+
43+ /* GD -> LE with global variable defined in executable */
1544 sethi %tgd_hi22(tls_gd), %g1
1645 add %g1, %tgd_lo10(tls_gd), %g1
1746 add %l7, %g1, %o0, %tgd_add(tls_gd)
1847 call __tls_get_addr, %tgd_call(tls_gd)
1948 nop
20- .size get_gdp, .-get_gdp
49+ nop;nop;nop;nop
50+
51+ /* LD -> LE with global variable defined in executable */
52+ sethi %tldm_hi22(tls_ld), %g1
53+ add %g1, %tldm_lo10(tls_ld), %g1
54+ add %l7, %g1, %o0, %tldm_add(tls_ld)
55+ call __tls_get_addr, %tldm_call(tls_ld)
56+ nop
57+ sethi %tldo_hix22(tls_ld), %g1
58+ xor %g1, %tldo_lox10(tls_ld), %g1
59+ add %o0, %g1, %g1, %tldo_add(tls_ld)
60+ nop;nop;nop;nop
61+
62+ /* IE -> LE with global variable defined in executable */
63+ sethi %tie_hi22(tls_ie), %g1
64+ add %g1, %tie_lo10(tls_ie), %g1
65+ ldx [%l7 + %g1], %g1, %tie_ldx(tls_ie)
66+ add %g7, %g1, %g1, %tie_add(tls_ie)
67+ nop;nop;nop;nop
68+
69+ ret
70+ restore