[llvm] r338173 - [llvm-objcopy] Make --strip-debug strip .zdebug* (zlib-gnu) sections

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 13:34:57 PDT 2018


GNU objcopy -g (STRIP_DEBUG) will strip .gdb_index

This is probably because sections marked as SEC_DEBUGGING will be
stripped. .debug .zdebug are modern while .line* .stab* should be very
uncommon, not sure about .gnu.linkonce.wi.* though.

binutils-gdb/bfd/elf.c:1053

      /* The debugging sections appear to be recognized only by name,
	 not any sort of flag.  Their SEC_ALLOC bits are cleared.  */
      if (name [0] == '.')
	{
	  const char *p;
	  int n;
	  if (name[1] == 'd')
	    p = ".debug", n = 6;
	  else if (name[1] == 'g' && name[2] == 'n')
	    p = ".gnu.linkonce.wi.", n = 17;
	  else if (name[1] == 'g' && name[2] == 'd')
	    p = ".gdb_index", n = 11; /* yes we really do mean 11.  */
	  else if (name[1] == 'l')
	    p = ".line", n = 5;
	  else if (name[1] == 's')
	    p = ".stab", n = 5;
	  else if (name[1] == 'z')
	    p = ".zdebug", n = 7;
	  else
	    p = NULL, n = 0;
	  if (p != NULL && strncmp (name, p, n) == 0)
	    flags |= SEC_DEBUGGING;
	}


On 2018-07-30, David Blaikie wrote:
>Might want to check what binutils objcopy does with .gdb_index too - sort of
>debug info section without the ".debug_" prefix.
>
>On Fri, Jul 27, 2018 at 3:51 PM Fangrui Song via llvm-commits <
>llvm-commits at lists.llvm.org> wrote:
>
>    Author: maskray
>    Date: Fri Jul 27 15:51:36 2018
>    New Revision: 338173
>
>    URL: http://llvm.org/viewvc/llvm-project?rev=338173&view=rev
>    Log:
>    [llvm-objcopy] Make --strip-debug strip .zdebug* (zlib-gnu) sections
>
>    This behavior matches GNU objcopy.
>
>    Modified:
>        llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
>
>    Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
>    URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/
>    llvm-objcopy.cpp?rev=338173&r1=338172&r2=338173&view=diff
>    ===========================================================================
>    ===
>    --- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
>    +++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Fri Jul 27 15:51:36 2018
>    @@ -185,6 +185,10 @@ LLVM_ATTRIBUTE_NORETURN void reportError
>     } // end namespace objcopy
>     } // end namespace llvm
>
>    +static bool IsDebugSection(const SectionBase &Sec) {
>    +  return Sec.Name.startswith(".debug") || Sec.Name.startswith(".zdebug");
>    +}
>    +
>     static bool IsDWOSection(const SectionBase &Sec) {
>       return Sec.Name.endswith(".dwo");
>     }
>    @@ -316,8 +320,7 @@ static void HandleArgs(const CopyConfig
>       // Removes:
>       if (!Config.ToRemove.empty()) {
>         RemovePred = [&Config](const SectionBase &Sec) {
>    -      return std::find(std::begin(Config.ToRemove), std::end
>    (Config.ToRemove),
>    -                       Sec.Name) != std::end(Config.ToRemove);
>    +      return find(Config.ToRemove, Sec.Name) != Config.ToRemove.end();
>         };
>       }
>
>    @@ -346,7 +349,7 @@ static void HandleArgs(const CopyConfig
>           case SHT_STRTAB:
>             return true;
>           }
>    -      return Sec.Name.startswith(".debug");
>    +      return IsDebugSection(Sec);
>         };
>
>       if (Config.StripSections) {
>    @@ -357,7 +360,7 @@ static void HandleArgs(const CopyConfig
>
>       if (Config.StripDebug) {
>         RemovePred = [RemovePred](const SectionBase &Sec) {
>    -      return RemovePred(Sec) || Sec.Name.startswith(".debug");
>    +      return RemovePred(Sec) || IsDebugSection(Sec);
>         };
>       }
>
>    @@ -385,8 +388,7 @@ static void HandleArgs(const CopyConfig
>       if (!Config.OnlyKeep.empty()) {
>         RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) {
>           // Explicitly keep these sections regardless of previous removes.
>    -      if (std::find(std::begin(Config.OnlyKeep), std::end
>    (Config.OnlyKeep),
>    -                    Sec.Name) != std::end(Config.OnlyKeep))
>    +      if (find(Config.OnlyKeep, Sec.Name) != Config.OnlyKeep.end())
>             return false;
>
>           // Allow all implicit removes.
>    @@ -408,8 +410,7 @@ static void HandleArgs(const CopyConfig
>       if (!Config.Keep.empty()) {
>         RemovePred = [Config, RemovePred](const SectionBase &Sec) {
>           // Explicitly keep these sections regardless of previous removes.
>    -      if (std::find(std::begin(Config.Keep), std::end(Config.Keep),
>    Sec.Name) !=
>    -          std::end(Config.Keep))
>    +      if (find(Config.Keep, Sec.Name) != Config.Keep.end())
>             return false;
>           // Otherwise defer to RemovePred.
>           return RemovePred(Sec);
>
>    _______________________________________________
>    llvm-commits mailing list
>    llvm-commits at lists.llvm.org
>    http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>

-- 
宋方睿


More information about the llvm-commits mailing list