<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Thanks for looking at this. I sent a separate email with the object file attached directly to you.</p>
<p>FWIW, using od -c to dump the string table, you can see that ^L (form feed), which is the character that ends up in the first N_SO string, immediately precedes  the directory path:<br>
</p>
<p><tt>0003220    2       -   g   d   w   a   r   f   -   4  \0  <b>\f   /   n   f</b><br>
0003240    <b>s   /   h   o   m   e   s   /   j   d   e   l   s   i   g   n</b><br>
0003260    <b>/   h   e   l   l   o   .   c</b>  \0   /   t   m   p  \0  \0  \0<br>
</tt></p>
<p>Seems like an off-by-one error in the linker, and gcc / gfortran just happens to tickle it.</p>
<p>Cheers, John D.<br>
</p>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 3/15/24 11:58, Adrian Prantl wrote:<br>
</div>
<blockquote type="cite" cite="mid:DF6E6C28-7FDA-44AD-B3F1-D8629D081387@apple.com">
<table style="cellpadding:0;border:0;cellspacing:0;display:table;width:100%;table-layout:fixed;border-collapse:seperate;float:none;" width="100%" cellspacing="0" cellpadding="0" border="0" align="left">
<tbody style="display:block;">
<tr>
<td cellpadding="7px 2px 7px 2px" style="padding:7px 2px 7px 2px;background-color:#A6A6A6;valign:middle" width="1px" valign="middle" bgcolor="#A6A6A6">
<br>
</td>
<td cellpadding="7px 5px 7px 15px" color="#212121" style="width:100%;background-color:#EAEAEA;padding:7px 5px 7px 15px;font-family:wf_segoe-ui_normal,Segoe UI,Segoe WP,Tahoma,Arial, sans-serif;font-size:12px;font-weight:normal;color:#212121;text-align:left;word-wrap:break-word;" width="100%" valign="middle" bgcolor="#EAEAEA">
<div>You don't often get email from <a class="moz-txt-link-abbreviated" href="mailto:aprantl@apple.com">
aprantl@apple.com</a>. <a href="https://aka.ms/LearnAboutSenderIdentification" moz-do-not-send="true">
Learn why this is important</a></div>
</td>
<td cellpadding="7px 5px 7px 5px" color="#212121" style="width:75px;background-color:#EAEAEA;padding:7px 5px 7px 5px;font-family:wf_segoe-ui_normal,Segoe UI,Segoe WP,Tahoma,Arial, sans-serif;font-size:12px;font-weight:normal;color:#212121;text-align:left;word-wrap:break-word;align:left" width="75px" valign="middle" bgcolor="#EAEAEA" align="left">
<br>
</td>
</tr>
</tbody>
</table>
<div>Could you send me an example .o file that reproduces the issue? I'm curious now.
<div><br>
</div>
<div>-- adrian<br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On Mar 15, 2024, at 7:41 AM, John DelSignore <a class="moz-txt-link-rfc2396E" href="mailto:JDelSignore@perforce.com">
<JDelSignore@perforce.com></a> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div>
<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="Tu5/jvUl4pZIg+1iBmv58249WgkPAMzjt88pujMPWC2lQkEjCfL+Z55ZJKYU+uT7BtPtudLFW+h9kcndt36hk/avF7x8dnNpZNqX1KfcICmo29ewPrBqYQS+DDID6HbYKtI+C1qNZWIwgFqpjfyFXKv5UTv7DHsb8O0TBFyikYI=" 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=""> 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>
</div>
</div>
</blockquote>
</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>