]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elflint: Recognize SHF_GNU_RETAIN as extra section flag.
authorMark Wielaard <mark@klomp.org>
Tue, 12 Jan 2021 10:35:10 +0000 (11:35 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 15 Jan 2021 10:43:01 +0000 (11:43 +0100)
SHF_GNU_RETAIN is like SHF_LINK_ORDER it can appear on any section
and should be ignored by elflint. Add all such flags to a new
EXTRA_SHFLAGS and use it consistently in check_sections.

https://sourceware.org/bugzilla/show_bug.cgi?id=27134

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/elflint.c

index 62aaad8fae2020d0be08a971f76fdc7933500632..bd76256e2fcd53af6570946b34bce50a9ea8b89f 100644 (file)
@@ -1,6 +1,12 @@
+2021-01-12  Mark Wielaard  <mark@klomp.org>
+
+       * elflint.c (EXTRA_SHFLAGS): New define.
+       (check_sections): Use EXTRA_SHFLAGS. Add SHF_GNU_RETAIN to
+       ALL_SH_FLAGS.
+
 2020-12-31  Sergei Trofimovich  <slyfox@gentoo.org>
 
-       * elflint.c (srction_flags_string): Add NEWFLAG for GNU_RETAIN,
+       * elflint.c (section_flags_string): Add NEWFLAG for GNU_RETAIN,
        ORDERED and EXCLUDE.
 
 2020-12-31  Sergei Trofimovich  <slyfox@gentoo.org>
index dcf7e199fbc96a55a072134f715bc37b7e078c61..6a946838c89952b2bcca6c3ecd42c28a050db058 100644 (file)
@@ -3681,6 +3681,13 @@ static const struct
    && !memcmp (special_sections[idx].name, string, \
               sizeof string - (prefix ? 1 : 0)))
 
+/* Extra section flags that might or might not be added to the section
+   and have to be ignored.  */
+#define EXTRA_SHFLAGS (SHF_LINK_ORDER \
+                      | SHF_GNU_RETAIN \
+                      | SHF_GROUP \
+                      | SHF_COMPRESSED)
+
 
 /* Indices of some sections we need later.  */
 static size_t eh_frame_hdr_scnndx;
@@ -3796,11 +3803,10 @@ section [%2d] '%s' has wrong type: expected %s, is %s\n"),
                if (special_sections[s].attrflag == exact
                    || special_sections[s].attrflag == exact_or_gnuld)
                  {
-                   /* Except for the link order, group bit and
+                   /* Except for the link order, retain, group bit and
                       compression flag all the other bits should
                       match exactly.  */
-                   if ((shdr->sh_flags
-                        & ~(SHF_LINK_ORDER | SHF_GROUP | SHF_COMPRESSED))
+                   if ((shdr->sh_flags & ~EXTRA_SHFLAGS)
                        != special_sections[s].attr
                        && (special_sections[s].attrflag == exact || !gnuld))
                      ERROR (_("\
@@ -3809,7 +3815,7 @@ section [%2zu] '%s' has wrong flags: expected %s, is %s\n"),
                             section_flags_string (special_sections[s].attr,
                                                   stbuf1, sizeof (stbuf1)),
                             section_flags_string (shdr->sh_flags
-                                                  & ~SHF_LINK_ORDER,
+                                                  & ~EXTRA_SHFLAGS,
                                                   stbuf2, sizeof (stbuf2)));
                  }
                else if (special_sections[s].attrflag == atleast)
@@ -3817,7 +3823,7 @@ section [%2zu] '%s' has wrong flags: expected %s, is %s\n"),
                    if ((shdr->sh_flags & special_sections[s].attr)
                        != special_sections[s].attr
                        || ((shdr->sh_flags
-                            & ~(SHF_LINK_ORDER | SHF_GROUP | SHF_COMPRESSED
+                            & ~(EXTRA_SHFLAGS
                                 | special_sections[s].attr
                                 | special_sections[s].attr2))
                            != 0))
@@ -3829,8 +3835,7 @@ section [%2zu] '%s' has wrong flags: expected %s and possibly %s, is %s\n"),
                             section_flags_string (special_sections[s].attr2,
                                                   stbuf2, sizeof (stbuf2)),
                             section_flags_string (shdr->sh_flags
-                                                  & ~(SHF_LINK_ORDER
-                                                      | SHF_GROUP),
+                                                  & ~EXTRA_SHFLAGS,
                                                   stbuf3, sizeof (stbuf3)));
                  }
 
@@ -3923,7 +3928,7 @@ section [%2zu] '%s': size not multiple of entry size\n"),
 #define ALL_SH_FLAGS (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR | SHF_MERGE \
                      | SHF_STRINGS | SHF_INFO_LINK | SHF_LINK_ORDER \
                      | SHF_OS_NONCONFORMING | SHF_GROUP | SHF_TLS \
-                     | SHF_COMPRESSED)
+                     | SHF_COMPRESSED | SHF_GNU_RETAIN)
       if (shdr->sh_flags & ~(GElf_Xword) ALL_SH_FLAGS)
        {
          GElf_Xword sh_flags = shdr->sh_flags & ~(GElf_Xword) ALL_SH_FLAGS;