<div dir="ltr">Hi Peter<div><br></div><div>Thanks for your reply. It seems that the mix of arm and thumb is determined by the target attribute inside the source code. Is it right?</div><div><br></div><div>May I understand like this, I think the '-mthumb' is a compiling flag. If no target information is provided. Then instruction mode will be determined by the compiling flag. If I set -mthumb, all the instructions will be in thumb mode. If I set nothing, all the instructions will be compiled into arm mode by default. What if I set -mthumb, but there is a target information specifying arm mode?</div><div><br></div><div>Besides, I looked at the link you provided, I don't know the valid value of target if I need the function to be compiled to thumb mode. Maybe something like  <span class="gmail-n" style="color:rgb(51,51,51)">__attribute__</span><span class="gmail-p" style="color:rgb(51,51,51)">((</span><span class="gmail-n" style="color:rgb(51,51,51)">target</span><span class="gmail-p" style="color:rgb(51,51,51)">(</span><span class="gmail-s" style="color:rgb(64,112,160)">"</span>thumbv7a-linux-gnueabi<span class="gmail-s" style="color:rgb(64,112,160)">"</span><span class="gmail-p" style="color:rgb(51,51,51)">)))? Thank you very much.</span></div><div><span class="gmail-p" style="color:rgb(51,51,51)"><br></span></div><div><span class="gmail-p" style="color:rgb(51,51,51)">Regards</span></div><div><span class="gmail-p" style="color:rgb(51,51,51)">Muhui</span></div></div><br><div class="gmail_quote"><div dir="ltr">Peter Smith <<a href="mailto:peter.smith@linaro.org">peter.smith@linaro.org</a>> 于2018年11月9日周五 上午12:17写道:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, 8 Nov 2018 at 15:26, Muhui Jiang via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi<br>
><br>
> I would like to use clang to cross compile the ARM binary. I hope the target binary contains both arm and thumb instruction sets.<br>
><br>
> I use the flag -mhwdiv=arm,thumb. I compiled several binaries. However, I found that the thumb mode instructions are few. Even for very big program like gcc. The number of thumb mode instruction is less than 100. I get the ground truth from the mapping table.<br>
><br>
> Maybe the flag I use is not right? I think there should be many thumb mode instructions. How do clang select thumb or arm mode when compiling? Many Thanks<br>
><br>
> Regards<br>
> Muhui<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
Hello Muhui,<br>
<br>
clang with a target like armv7a-linux-gnueabihf will default to<br>
compiling all the functions in the file in Arm state. If the option<br>
-mthumb or a target like thumbv7a-linux-gnueabi is used then all of<br>
the functions will be compiled in Thumb state. Depending on how the<br>
flags vary across the program will determine the mix of Arm and Thumb<br>
in the binary.<br>
<br>
Off the top of my head I think that you can use the target attribute<br>
to change the state of individual function<br>
<a href="https://clang.llvm.org/docs/AttributeReference.html#target" rel="noreferrer" target="_blank">https://clang.llvm.org/docs/AttributeReference.html#target</a><br>
<br>
Peter<br>
</blockquote></div>