[lld] 875d24c - [ELF] Avoid list initialization with incomplete unique_ptr<OutputSection> member to work around clang < 16

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 17 10:16:07 PST 2024


Author: Fangrui Song
Date: 2024-11-17T10:16:01-08:00
New Revision: 875d24c2302cf0194fdd44b012623f395a705863

URL: https://github.com/llvm/llvm-project/commit/875d24c2302cf0194fdd44b012623f395a705863
DIFF: https://github.com/llvm/llvm-project/commit/875d24c2302cf0194fdd44b012623f395a705863.diff

LOG: [ELF] Avoid list initialization with incomplete unique_ptr<OutputSection> member to work around clang < 16

Commit 5b1b6a62b8bd986adc711d0c0be5b6a8182be263 introduced the following
issue for older clang with libstdc++

```
In file included from /home/ray/llvm/lld/ELF/EhFrame.cpp:18:
In file included from /home/ray/llvm/lld/ELF/EhFrame.h:12:
In file included from /home/ray/llvm/lld/include/lld/Common/LLVM.h:21:
In file included from /home/ray/llvm/llvm/include/llvm/Support/Casting.h:20:
In file included from /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/memory:78:
/usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:91:16: error: invalid application of 'sizeof' to an incomplete type 'lld::elf::OutputSection'
        static_assert(sizeof(_Tp)>0,
                      ^~~~~~~~~~~
/usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/unique_ptr.h:398:4: note: in instantiation of member function 'std::default_delete<lld::elf::OutputSection>::operator()' requested here
          get_deleter()(std::move(__ptr));
          ^
/home/ray/llvm/lld/ELF/Config.h:574:19: note: in instantiation of member function 'std::unique_ptr<lld::elf::OutputSection>::~unique_ptr' requested here
  OutSections out{};
                  ^
```

Added: 
    

Modified: 
    lld/ELF/Config.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 2cca0a0bf71859..a2836733c2715e 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -567,11 +567,11 @@ struct Ctx : CommonLinkerContext {
   struct OutSections {
     std::unique_ptr<OutputSection> elfHeader;
     std::unique_ptr<OutputSection> programHeaders;
-    OutputSection *preinitArray;
-    OutputSection *initArray;
-    OutputSection *finiArray;
+    OutputSection *preinitArray = nullptr;
+    OutputSection *initArray = nullptr;
+    OutputSection *finiArray = nullptr;
   };
-  OutSections out{};
+  OutSections out;
   SmallVector<OutputSection *, 0> outputSections;
   std::vector<Partition> partitions;
 


        


More information about the llvm-commits mailing list