<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/162954>162954</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [dsymutil] `--linker=parallel` causes self-recurring typedef in DIE for `std::string`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          royitaqi
      </td>
    </tr>
</table>

<pre>
    # TL;DR

With `--linker=parallel`, the generated dSYM contains a DIE (see below), which is a typedef of itself (see the address of the `DW_TAG_typedef` is identical to the address of the `DW_AT_type`).
```
0x00004cb1: DW_TAG_typedef
 DW_AT_type     (0x00004cb1 "string")
              DW_AT_name        ("string")
 DW_AT_decl_line        (45)
 DW_AT_decl_file        ("/Applications/Xcode_26.0.0_17A324_fb.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__fwd/string.h")
```

This happens on macOS. Not sure if it happens on other OS.

This causes LLDB to enter infinite recursion when trying to understand this type. See [stack trace](https://gist.github.com/royitaqi/873a57af77c956902bfe30701c7bd294).


# Repro steps

**Step 1: Create the following `main.cpp`:**

```
#include <string>
#include <iostream>

int main() {
  std::string f = "Hello World";
  std::cout << f << std::endl;
}
```

**Step 2: Run `dsymutil` WITH `--linker=parallel` to repro the issue (on macOS):**

```
xcrun clang++ -g -O0 -c main.cpp
xcrun clang++ -g -O0 main.o
~/public_llvm/build/bin/dsymutil --verify-dwarf=all --linker=parallel -o a.out.dSYM a.out
dddd a.out.dSYM --name=string
lldb a.out -o "b main.cpp:6" -o "r" -o "p f"
```

I see these output: https://gist.github.com/royitaqi/1afb74beccfcd011021e339e1dc76e0d

Observe:
* The DIE contains a "string" which is a typedef of itself.
* The `--verify-dwarf=all` doesn't catch this issue.
* If you attach an lldb to the above lldb, you will see the above call stack.

**(optional) Step 3: Run `dsymutil` WITHOUT `--linker=parallel` as a comparison:**

```
xcrun clang++ -g -O0 -c main.cpp
xcrun clang++ -g -O0 main.o
~/public_llvm/build/bin/dsymutil --verify-dwarf=all -o a.out.dSYM a.out
dddd a.out.dSYM --name=string
lldb a.out -o "b main.cpp:6" -o "r" -o "p f"
```

I see these output: https://gist.github.com/royitaqi/e83bb8b986fef3556f2e268e8c7a6eee

Observe:
* The DIE contains one "string" which is a typedef of another "string", which is the actual `std::basic_string`.
* The "string" type is understood and is printed correctly by lldb.

--

cc @clayborg 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcVk9v47oR_zT0ZWCBoizZOvigxM99i-5rik2KfT0ZFDmy2GVIlaSS50s_ezGynHiTbrA9toGAyOT80fzmN39kjOboELesvGHlbiHH1PuwDf5kkvynWbRen7ZMFPDwmRU3uy-MN4w3X03qgVV8ubTGfcPAit0gg7QWLas4E7eQeoQjOgwyoQZ9__ffQHmXpHERJOw-_QJMbCIitGj9MxM1KT33RvVgSCKdBtTYge_ApIi2u8iTYal1wBjpkn6yiu--Hh6aPx1mLVZxsmI0umSUtJD8j_Wah0lt-u46o_gqPj-84X9wzvlKtTkrGnjjhU8nF31eM7F5lQcmREzBuCMTguLjDXz3d1Z18nFW_Q_yZxGNyh6scbPcqnx_2xn7aoWJfTMM1iiZjHeRif3vyms8iCrjGT_k66YQq0PXZnIYmNjfepfQJZLb4RNaP2BgYv9XK1PnwyOd_ybV3f3v2TAfvZG83_35Sijqb0zsx0g3xik7amRir5i4mZ79U87E_nDonjUT-3PAWf8S8jX2jDcPvYnQy2FAF8E7eCQfGfzFJ4hjQDDEjmsBn3oMcHefXekrOUaM8Pnz7oaIgC5hAOM640xCCKjGEI138NyjgxROxh1JbnQaQ0zSaUhkhpKcwT0isPImJqm-QQpSISt3TGz6lIbIioaJPRP7o4kpO5rUj22mPAF2KSgm9pt1Icu17NZrVZdVzUXbYcHXPFfrVot6daHh-REFfMEheIgJh3g5pOc-4QATL28DynQujc5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