<p class="p1">The debugger shows that this forwardToGcc path does get hit. Setting a breakpoint just before it, I find my option:</p><p class="p1"><span class="s1">6681<span class="Apple-converted-space"> </span>for (const auto &A : Args) {</span><br></p><p class="p1"><span class="s1">6682<span class="Apple-converted-space"> </span>if (A->getOption().matches(options::OPT_fmyopt_EQ)) {<span class="Apple-converted-space"> </span></span><br></p><p class="p1"><span class="s1">6683 <span class="Apple-converted-space"> </span>printf("here\n");</span><br></p><p class="p1"><span class="s1">6684<span class="Apple-converted-space"> </span>}</span><br></p><p class="p1"><span class="s1">6685<span class="Apple-converted-space"> </span>if (forwardToGCC(A->getOption())) {</span><br></p><p class="p1"><br></p><div><br></div><div><span class="s1">$3 = {</span><br></div><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>Opt = {</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>Info = 0x7ffff43f00d0 <InfoTable+28336>,</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>Owner = 0x45c170</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>},</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>BaseArg = 0x0,</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>Spelling = {</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>static npos = 18446744073709551615,</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>Data = 0x7fffffffdd1e "-fmyopt=extended",<span class="Apple-converted-space"> </span></span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>Length = 10</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>},</span><br></p><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>...</span><br></p><p class="p1"><span class="s1">}</span><br></p><p class="p1"><br></p><div>then in the forward code:<br></div><div><br></div><p class="p1"><span class="s1">/home/pjoot/<a href="http://llvm.pragmas/tools/clang/lib/Driver/Tools.cpp:295">llvm.pragmas/tools/clang/lib/Driver/Tools.cpp:295</a></span><br></p><p class="p1"><span class="s1">295<span class="Apple-converted-space"> </span>auto pk = O.getKind() != Option::InputClass ;</span><br></p><p class="p1"><span class="s1">296<span class="Apple-converted-space"> </span>auto pd = O.hasFlag(options::DriverOption) ;</span><br></p><p class="p1"><span class="s1">297<span class="Apple-converted-space"> </span>auto pl = O.hasFlag(options::LinkerInput);</span><br></p><p class="p1"><span class="s1">298<span class="Apple-converted-space"> </span>return pk && !pd && !pl;</span><br></p><p class="p1"><span class="s1">$4 = true</span><br></p><p class="p1"><span class="s1">$5 = false</span><br></p><p class="p1"><span class="s1">$6 = false</span><br></p><div><span class="s1">DriverOption and LinkerInput are both false so the result is true:</span><br></div><p class="p1"><span class="s1">$7 = true</span><br></p><div class="protonmail_signature_block "><div class="protonmail_signature_block-user "><div>I then see my flag get inserted into the CmdArgs for the gcc command line (although I can't confirm easily in the debugger, since the SmallString class is garbage to gdb).<br></div><div><br></div><div>Perhaps I should be setting DriverOption in Options.td along with CC1Option?<br></div><div><br></div><div>--<br></div><div>Peeter<br></div></div><div class="protonmail_signature_block-proton protonmail_signature_block-empty"><br></div></div><div><br></div><blockquote class="protonmail_quote" type="cite"><div>-------- Original Message --------<br></div><div>Subject: Re: [cfe-dev] how to avoid passing new clang front end option to the linker?<br></div><div>Local Time: March 15, 2017 7:19 PM<br></div><div>UTC Time: March 15, 2017 11:19 PM<br></div><div>From: mehdi.amini@apple.com<br></div><div>To: Peeter Joot <peeterjoot@protonmail.com><br></div><div>"Robinson, Paul" <paul.robinson@sony.com>, cfe-dev@lists.llvm.org <cfe-dev@lists.llvm.org><br></div><div><br></div><div><br></div><div><blockquote class="" type="cite"><div class="">On Mar 15, 2017, at 12:11 PM, Peeter Joot via cfe-dev <<a class="" href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer nofollow noopener">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div><br></div><div class=""><div class="">I think that I've probably declared my option inappropriately. It was:<br></div><div class=""><br></div><div class="">// Options.td<br></div><div class=""><span class="s1">def fmyopt_EQ : Joined<["-"], "fmyopt=">, Group<f_clang>, Flags<[CC1Option]>,</span><br></div><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>HelpText<"...">;</span><br></p><div class="">I think that the choice of whether or not to propagate it to the linker comes from here:<br></div><div class=""><br></div><p class="p1"><span class="s1">static</span><span class="s2"> </span><span class="s1">bool</span><span class="s2"> </span><span class="s3">forwardToGCC</span><span class="s2">(</span><span class="s1">const</span><span class="s2"> Option &O) {</span><br></p><p class="p2"><span class="s4"><span class="Apple-converted-space"> </span></span><span class="s2">// Don't forward inputs from the original command line.<span class="Apple-converted-space"> </span>They are added from</span><br></p><p class="p2"><span class="s4"><span class="Apple-converted-space"> </span></span><span class="s2">// InputInfoList.</span><br></p><p class="p1"><span class="s2"><span class="Apple-converted-space"> </span></span><span class="s5">return</span><span class="s2"> O.</span><span class="s3">getKind</span><span class="s2">() != Option::InputClass &&</span><br></p><p class="p1"><span class="s2"><span class="Apple-converted-space"> </span>!O.</span><span class="s3">hasFlag</span><span class="s2">(options::DriverOption) && !O.</span><span class="s3">hasFlag</span><span class="s2">(options::LinkerInput);</span><br></p><p class="p1"><span class="s2">}</span><br></p><div class=""><br></div><div class=""><span class="s2">i.e. the LinkerInput flag. Perhaps this is implied by CC1Option in my Options.td line?</span><br></div></div></blockquote><div><br></div><div><br></div><div>I’m not sure, there is a ! in front the the LinkerInput test, so it’ll return true if it is *not* a LinkerInput.<br></div><div><br></div><div><br></div><blockquote class="" type="cite"><div class=""><div class=""><span class="s2">I tried changing to</span><br></div><div class=""><br></div><div class=""><span class="s1">def fmyopt_EQ : Joined<["-"], "fmyopt=">, Group<f_clang>, Flags<[DriverOption]>,</span><br></div><p class="p1"><span class="s1"><span class="Apple-converted-space"> </span>HelpText<"...”>;</span><br></p></div></blockquote><div><br></div><div>Maybe:<br></div><div><br></div><div><blockquote class="" type="cite"><div class=""><span class="s1">def fmyopt_EQ : Joined<["-"], "fmyopt=">, Group<f_clang>, Flags<[DriverOption, CC1Option]>,</span><br></div></blockquote><div class=""><div class=""><span class="s1"></span><br></div></div><div class=""><span class="s1">?</span><br></div><div class=""><span class="s1"></span><br></div><div class=""><span class="s1">— </span><br></div><div class=""><span class="s1">Mehdi</span><br></div><div class=""><span class="s1"></span><br></div></div><div><br></div><div><br></div><blockquote class="" type="cite"><div class=""><div class="">but now my option is no longer recognized in the compilation phase.<br></div><div class=""><br></div><div class="">Hmm, wondering if I should have put this in CC1Options.td instead, which I just spotted?<br></div><div class=""><br></div><div class=" protonmail_signature_block"><div class="protonmail_signature_block-user "><div class="">--<br></div><div class="">Peeter<br></div></div><div class="protonmail_signature_block-proton protonmail_signature_block-empty"><br></div></div><div class=""><br></div><blockquote type="cite" class="protonmail_quote"><div class="">-------- Original Message --------<br></div><div class="">Subject: RE: [cfe-dev] how to avoid passing new clang front end option to the linker?<br></div><div class="">Local Time: March 15, 2017 2:25 PM<br></div><div class="">UTC Time: March 15, 2017 6:25 PM<br></div><div class="">From: <a class="" href="mailto:paul.robinson@sony.com" rel="noreferrer nofollow noopener">paul.robinson@sony.com</a><br></div><div class="">To: Peeter Joot <<a class="" href="mailto:peeterjoot@protonmail.com" rel="noreferrer nofollow noopener">peeterjoot@protonmail.com</a>><br></div><div class=""><a class="" href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer nofollow noopener">cfe-dev@lists.llvm.org</a> <<a class="" href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer nofollow noopener">cfe-dev@lists.llvm.org</a>><br></div><div class=""><br></div><div class=""><br></div><div class="WordSection1"><p class="MsoNormal"><span style="color:rgb(31, 73, 125)" class="colour"><span style="font-family:Calibri, sans-serif" class="font"><span style="font-size:11pt" class="size">The linker command line would be constructed in the driver (clang/lib/Driver/…) and exactly where the code is depends on your triple. You could grep for 'Linker::ConstructJob'
and see what looks most likely, or try stepping through the driver in a debugger to see which one is invoked. I am a little surprised that arbitrary –f options would be passed through in the link phase.</span></span></span><br></p><p class="MsoNormal"><a class="" name="_MailEndCompose"><span style="color:rgb(31, 73, 125)" class="colour"><span style="font-family:Calibri, sans-serif" class="font"><span style="font-size:11pt" class="size">HTH,</span></span></span></a><br></p><p class="MsoNormal"><span style="color:rgb(31, 73, 125)" class="colour"><span style="font-family:Calibri, sans-serif" class="font"><span style="font-size:11pt" class="size">--paulr</span></span></span><br></p><p class="MsoNormal"><span style="color:rgb(31, 73, 125)" class="colour"><span style="font-family:Calibri, sans-serif" class="font"><span style="font-size:11pt" class="size"> </span></span></span><br></p><div class="" style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div class=""><div class="" style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b class=""><span style="font-family:Tahoma, sans-serif" class="font"><span style="font-size:10pt" class="size">From:</span></span></b><span style="font-family:Tahoma, sans-serif" class="font"><span style="font-size:10pt" class="size"> cfe-dev [<a class="" href="mailto:cfe-dev-bounces@lists.llvm.org" rel="noreferrer nofollow noopener">mailto:cfe-dev-bounces@lists.llvm.org</a>] <b class="">On Behalf Of </b>Peeter Joot via cfe-dev<br class=""> <b class="">Sent:</b> Wednesday, March 15, 2017 8:10 AM<br class=""> <b class="">To:</b> <a class="" href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer nofollow noopener">cfe-dev@lists.llvm.org</a><br class=""> <b class="">Subject:</b> [cfe-dev] how to avoid passing new clang front end option to the linker?</span></span></p></div></div><p class="MsoNormal"> <br></p><div class=""><p class="MsoNormal">I'm attempting to implement a new clang front end option for my project (<span class="s1">-fmyopt=blah)</span>, and have made the changes required that I can access and act on it in my Target class when compiling. When linking, it causes
a bit of trouble, as clang passes it on to gcc in the link phase:<br></p></div><p class="p1"><span class="apple-converted-space"> </span><span class="s1">"/usr/lib64/ccache/gcc" -g -D QSIZE -fpic -MD -fmyopt=blah -v -m64 -o tryit /run/user/1002/tryit-46641b.o</span><br></p><p class="p1">which gcc objects to. <br></p><div class=""><p class="MsoNormal"> <br></p></div><div class=""><p class="MsoNormal">What part of the code is the link command line constructed in, and what is the mechanism used to select which options get passed to other stages (or an example of that)?<br></p></div><div class=""><p class="MsoNormal"> <br></p></div><div class=""><div class=""><div class=""><p class="MsoNormal">--<br></p></div><div class=""><p class="MsoNormal">Peeter<br></p></div></div><div class=""><p class="MsoNormal"> <br></p></div></div><div class=""><p class="MsoNormal"> <br></p></div></div></div></blockquote><div class=""><br></div><div>_______________________________________________<br></div><div>cfe-dev mailing list<br></div><div><a class="" href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer nofollow noopener">cfe-dev@lists.llvm.org</a><br></div><div>http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br></div></div></blockquote></div></blockquote><div><br></div>