[llvm] [XCOFF][obj2yaml] support parsing auxiliary symbols for XCOFF (PR #70642)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 12:48:51 PST 2023


================
@@ -282,45 +282,53 @@ static void auxSymMapping(IO &IO, XCOFFYAML::SectAuxEntForStat &AuxSym) {
 
 void MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>>::mapping(
     IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym) {
-  assert(!IO.outputting() && "We don't dump aux symbols currently.");
   const bool Is64 =
       static_cast<XCOFFYAML::Object *>(IO.getContext())->Header.Magic ==
       (llvm::yaml::Hex16)XCOFF::XCOFF64;
   XCOFFYAML::AuxSymbolType AuxType;
+  if (IO.outputting())
+    AuxType = AuxSym.get()->Type;
   IO.mapRequired("Type", AuxType);
   switch (AuxType) {
   case XCOFFYAML::AUX_EXCEPT:
     if (!Is64)
       IO.setError("an auxiliary symbol of type AUX_EXCEPT cannot be defined in "
                   "XCOFF32");
-    AuxSym.reset(new XCOFFYAML::ExcpetionAuxEnt());
+    if (!IO.outputting())
+      AuxSym.reset(new XCOFFYAML::ExcpetionAuxEnt());
----------------
diggerlin wrote:

suggestion add a lambda helper function

```
 auto ResetAuxSym =
      [&](auto* AuxEnt) {
        if (!IO.outputting())
          AuxSym.reset(AuxEnt);
      };
```

and then change the code 
```
 if (!IO.outputting())
      AuxSym.reset(new XCOFFYAML::ExcpetionAuxEnt()); 
```
  to 
  
 ` ResetAuxSym (new XCOFFYAML::ExcpetionAuxEnt());`

https://github.com/llvm/llvm-project/pull/70642


More information about the llvm-commits mailing list