[clang] 8ad092f - [cc1as] Respect -mrelax-all

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 28 09:42:49 PDT 2024


Author: Fangrui Song
Date: 2024-04-28T09:42:43-07:00
New Revision: 8ad092f126bd1d6f9fe6006eba1e3115a080235e

URL: https://github.com/llvm/llvm-project/commit/8ad092f126bd1d6f9fe6006eba1e3115a080235e
DIFF: https://github.com/llvm/llvm-project/commit/8ad092f126bd1d6f9fe6006eba1e3115a080235e.diff

LOG: [cc1as] Respect -mrelax-all

So that `clang -c -mrelax-all a.s` sets MCRelaxAll and assembles JMP/JCC
to a near jump instead of silently ignoring `-mrelax-all`.

Added: 
    clang/test/Misc/cc1as-relax-all.s

Modified: 
    clang/tools/driver/cc1as_main.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/Misc/cc1as-relax-all.s b/clang/test/Misc/cc1as-relax-all.s
new file mode 100644
index 00000000000000..e76fc6f61babb9
--- /dev/null
+++ b/clang/test/Misc/cc1as-relax-all.s
@@ -0,0 +1,13 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -cc1as -triple x86_64 -filetype obj -mrelax-all %s -o %t.o
+// RUN: llvm-objdump -d %t.o | FileCheck %s
+
+// CHECK:      <.text>:
+// CHECK-NEXT:   0: e9 06 00 00 00                jmp     0xb <foo>
+// CHECK-NEXT:   5: 0f 84 00 00 00 00             je      0xb <foo>
+// CHECK-EMPTY:
+
+jmp foo
+je foo
+
+foo: ret

diff  --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 5498c3f9d4a20d..86afe22fac24cc 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -426,6 +426,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
   assert(MRI && "Unable to create target register info!");
 
   MCTargetOptions MCOptions;
+  MCOptions.MCRelaxAll = Opts.RelaxAll;
   MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;
   MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical;
   MCOptions.X86RelaxRelocations = Opts.RelaxELFRelocations;


        


More information about the cfe-commits mailing list