<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi Adrian,</p>
<p>Thanks for the reply. As far as I can tell, neither gcc nor gfortran produce N_SO stabs when -gdwarf-4 is used. It is the Apple ld-classic linker that is generating the N_SO stabs and inserting them into the Mach-O nlist symbol table. I believe that the
linker is reading the DWARF information out of the object file and using the compilation unit DIE to determine the string values for the N_SO stabs.</p>
<p>In the newest set of Apple ld sources I could find, I can see that the following function in OutputFile.cpp generates N_SO and N_OSO stabs:<br>
</p>
<p><tt> void OutputFile::synthesizeDebugNotes(ld::Internal& state)</tt></p>
<p>and seems to be using the DWARF information.</p>
<p>My guess is that there is something about the way gcc and gfortran generate the compilation unit DIE that causes the linker to generate:</p>
<p>N_SO <<i>compilation-directory</i>><<i>random-control-character</i>><<i>directory-path-of-file-name</i>><br>
N_SO <<i>basename-of-file-name</i>><br>
</p>
<p>For example:</p>
<p>dc3-mac-tvt4 39 03/15 10:38 /tmp % gcc-mp-13 -gdwarf-4 ~/hello.c -c<br>
dc3-mac-tvt4 40 03/15 10:38 /tmp % gcc-mp-13 hello.o -o hello<br>
dc3-mac-tvt4 41 03/15 10:39 /tmp % nm -ap hello | cat -v | grep -F ' SO '<br>
0000000000000000 - 01 0000 SO <br>
0000000000000000 - 00 0000 SO /tmp/^L/nfs/homes/jdelsign/<br>
0000000000000000 - 00 0000 SO hello.c<br>
0000000000000000 - 01 0000 SO <br>
0000000000000000 - 00 0000 SO /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc13/gcc13/work/build/x86_64-apple-darwin23/libgcc/^A/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc13/gcc13/work/gcc-13.2.0/libgcc/<br>
0000000000000000 - 00 0000 SO emutls.c<br>
0000000000000000 - 01 0000 SO <br>
dc3-mac-tvt4 42 03/15 10:39 /tmp % <br>
</p>
<p>Notice that the control characters in two "first" SO stabs.</p>
<p>Do you agree this is a linker bug?<br>
</p>
<p>Thanks, John D.<br>
</p>
<p>On 3/14/24 14:34, Adrian Prantl wrote:</p>
<blockquote type="cite" cite="mid:24F73C7D-1293-43B1-9C91-4BB5F5D1E7F7@apple.com">
<div>
<div>The N_OSO stabs entries are indeed added by the linker (<a href="https://wiki.dwarfstd.org/Apple's_%22Lazy%22_DWARF_Scheme.md" originalsrc="https://wiki.dwarfstd.org/Apple's_%22Lazy%22_DWARF_Scheme.md" shash="AfzzVRectHXtmt7KyIHO1OdmfNXekuGn+sKkRDnih/YHfnzq4awURCjSZwCH8OuO2B1eb1579OJxoLKMUKFGWjicGZsIHTm6lpZGLgezjarnlnnLTVi39uDTb52foGMSaCPxfZPKsHTCFk+6i33uvMj0q1Kzz+Wmfbp75QG3FnU=" moz-do-not-send="true">https://wiki.dwarfstd.org/Apple's_%22Lazy%22_DWARF_Scheme.md</a>). </div>
<div>Having done a quick scan through the linker sources I was not able to pinpoint the place where this path concatenation is happening.</div>
<div><br>
</div>
<div>> FWIW, I have not seen a similar problem with Apple's "cc", which is clang compiler. It does not generate the working directory in the N_SO stabs:</div>
<div><br class="Apple-interchange-newline">
</div>
<div>Assuming that that is indeed the root cause, it <i>might</i> be best to modify gfortran to no longer emit N_SO stabs entries in the object file.</div>
<div><br>
</div>
<div>Adrian</div>
<div><br>
</div>
<div><br>
</div>
<br>
<br>
<div align="center">
<table class="MsoTableGrid" style="border-collapse:collapse;border:none" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td style="width:399.35pt;border:double #FFC000 1.5pt;background:#FFFBEF;padding:0in 5.4pt 0in 5.4pt" width="532" valign="top">
<p class="MsoNormal"><b><span style="color:#BF8F00">CAUTION:</span></b><span style="color:black"> This email originated from outside of the organization. Do not click on links or open attachments unless you recognize the sender and know the content is safe.</span></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</blockquote>
<br>
<p><span style="font-size:8.0pt;color:#A6A6A6;font-style:italic">This e-mail may contain information that is privileged or confidential. If you are not the intended recipient, please delete the e-mail and any attachments and notify us immediately.</span></p>
<br>
</body>
</html>