Author: marius
Date: Thu May 17 21:49:34 2018
New Revision: 333770
URL: https://svnweb.freebsd.org/changeset/base/333770

Log:
  MFC: r333600 (phil)
  
  Handle thread-local storage (TLS) segments correctly when
  copying (objcopy) and displaying (readelf) them.
  
  PR:           227552
  Submitted by: kaiw (maintainer)
  Approved by:  re (gjb)

Modified:
  stable/11/contrib/elftoolchain/elfcopy/elfcopy.h
  stable/11/contrib/elftoolchain/elfcopy/sections.c
  stable/11/contrib/elftoolchain/elfcopy/segments.c
  stable/11/contrib/elftoolchain/readelf/readelf.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/elftoolchain/elfcopy/elfcopy.h
==============================================================================
--- stable/11/contrib/elftoolchain/elfcopy/elfcopy.h    Thu May 17 21:39:15 
2018        (r333769)
+++ stable/11/contrib/elftoolchain/elfcopy/elfcopy.h    Thu May 17 21:49:34 
2018        (r333770)
@@ -127,6 +127,7 @@ struct section {
        uint64_t         cap;   /* section capacity */
        uint64_t         align; /* section alignment */
        uint64_t         type;  /* section type */
+       uint64_t         flags; /* section flags */
        uint64_t         vma;   /* section virtual addr */
        uint64_t         lma;   /* section load addr */
        uint64_t         pad_sz;/* section padding size */

Modified: stable/11/contrib/elftoolchain/elfcopy/sections.c
==============================================================================
--- stable/11/contrib/elftoolchain/elfcopy/sections.c   Thu May 17 21:39:15 
2018        (r333769)
+++ stable/11/contrib/elftoolchain/elfcopy/sections.c   Thu May 17 21:49:34 
2018        (r333770)
@@ -411,6 +411,7 @@ create_scn(struct elfcopy *ecp)
                        s->sz           = ish.sh_size;
                        s->align        = ish.sh_addralign;
                        s->type         = ish.sh_type;
+                       s->flags        = ish.sh_flags;
                        s->vma          = ish.sh_addr;
 
                        /*

Modified: stable/11/contrib/elftoolchain/elfcopy/segments.c
==============================================================================
--- stable/11/contrib/elftoolchain/elfcopy/segments.c   Thu May 17 21:39:15 
2018        (r333769)
+++ stable/11/contrib/elftoolchain/elfcopy/segments.c   Thu May 17 21:49:34 
2018        (r333770)
@@ -79,6 +79,8 @@ add_to_inseg_list(struct elfcopy *ecp, struct section 
                        continue;
                if (s->vma + s->sz > seg->vaddr + seg->msz)
                        continue;
+               if (seg->type == PT_TLS && ((s->flags & SHF_TLS) == 0))
+                       continue;
 
                insert_to_inseg_list(seg, s);
                if (seg->type == PT_LOAD)

Modified: stable/11/contrib/elftoolchain/readelf/readelf.c
==============================================================================
--- stable/11/contrib/elftoolchain/readelf/readelf.c    Thu May 17 21:39:15 
2018        (r333769)
+++ stable/11/contrib/elftoolchain/readelf/readelf.c    Thu May 17 21:49:34 
2018        (r333770)
@@ -2377,11 +2377,22 @@ dump_phdr(struct readelf *re)
                }
                printf("   %2.2d     ", i);
                /* skip NULL section. */
-               for (j = 1; (size_t)j < re->shnum; j++)
-                       if (re->sl[j].addr >= phdr.p_vaddr &&
-                           re->sl[j].addr + re->sl[j].sz <=
+               for (j = 1; (size_t)j < re->shnum; j++) {
+                       if (re->sl[j].off < phdr.p_offset)
+                               continue;
+                       if (re->sl[j].off + re->sl[j].sz >
+                           phdr.p_offset + phdr.p_filesz &&
+                           re->sl[j].type != SHT_NOBITS)
+                               continue;
+                       if (re->sl[j].addr < phdr.p_vaddr ||
+                           re->sl[j].addr + re->sl[j].sz >
                            phdr.p_vaddr + phdr.p_memsz)
-                               printf("%s ", re->sl[j].name);
+                               continue;
+                       if (phdr.p_type == PT_TLS &&
+                           (re->sl[j].flags & SHF_TLS) == 0)
+                               continue;
+                       printf("%s ", re->sl[j].name);
+               }
                printf("\n");
        }
 #undef PH_HDR
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to