https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88386

            Bug ID: 88386
           Summary: LTRANS DWO files are not removed when using LTO +
                    Split Dwarf
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antonio.di.monaco at sap dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 45168
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45168&action=edit
Patch for dwo unlink in lto-wrapper

When using -flto and -gsplit-dwarf, several LTRANS objects and related dwo
files are created in the temp directory, but only the objects files are removed
after the compilation. So, DWOs are accumulated in the temp directory, causing
slowdowns and disk space waste.

To reproduce the issue, just build the following code:

main.cpp:
#include "A.hpp"

int main(int, char **)
{
  A a;

  a.f();

  return 0;
}

A.cpp:
#include <iostream>

#include "A.hpp"

A::A()
{

}

void A::f()
{
  std::cout << "Hello world" << std::endl;
}

A.hpp:
class A
{
public:
  A();

  void f();
};


and build it with:

g++ -flto -gsplit-dwarf -O2 -I. -o main.o -c main.cpp
g++ -flto -gsplit-dwarf -O2 -I. -o A.o -c A.cpp
g++ -flto -gsplit-dwarf -O2 -I. -o test main.o A.o

According to strace, objcopy creates the dwo file and strips DWARF from the
original .o file:

198527:execve("/usr/bin/objcopy", ["objcopy", "--extract-dwo",
"/tmp/ccLgXPla.ltrans0.ltrans.o", "/tmp/ccLgXPla.ltrans0.ltrans.dwo"], [/* 94
vars */]) = 0
198528:execve("/usr/bin/objcopy", ["objcopy", "--strip-dwo",
"/tmp/ccLgXPla.ltrans0.ltrans.o"], [/* 94 vars */]) = 0

But only the .o is then removed later on:

198520:unlink("/tmp/ccLgXPla.ltrans0.ltrans.o") = 0

I've enclosed a proposal to fix this, that removes the dwo at the lto-wrapper
exit. The ideal would be to avoid the creation of the DWO file at all, if it's
not used during the lto-wrapper stage, but I'm not sure.

I guess the bug is present also in previous 6.x series.

Thanks,
Antonio

Reply via email to