Skip to content

[llvm-objdump] Print ... even if a data mapping symbol is active #109553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Sep 21, 2024

Swap !DisassembleZeroes and if (DumpARMELFData) conditions so that
in the false DisassembleZeroes case (default), ... will be printed for
long consecutive zeroes, even when a data mapping symbol is active.

This is especially useful for certain lld tests that insert a huge
padding within a code section. Without ... the output will be huge.

Created using spr 1.3.5-bogner
@llvmbot
Copy link
Member

llvmbot commented Sep 21, 2024

@llvm/pr-subscribers-mc
@llvm/pr-subscribers-backend-arm
@llvm/pr-subscribers-llvm-binary-utilities
@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: Fangrui Song (MaskRay)

Changes

Swap !DisassembleZeroes and if (DumpARMELFData) conditions so that
in the false DisassembleZeroes case (default), ... will be printed for
long consecutive zeroes, even when a data mapping symbol is active.

This is especially useful for certain lld tests that insert a huge
padding within a code section. Without ... the output will be huge.


Full diff: https://github.com/llvm/llvm-project/pull/109553.diff

4 Files Affected:

  • (modified) lld/test/ELF/aarch64-undefined-weak.s (+1-1)
  • (added) llvm/test/tools/llvm-objdump/ELF/AArch64/zeroes.test (+66)
  • (added) llvm/test/tools/llvm-objdump/ELF/ARM/zeroes.test (+47)
  • (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+18-17)
diff --git a/lld/test/ELF/aarch64-undefined-weak.s b/lld/test/ELF/aarch64-undefined-weak.s
index f4628453ec3fea..015f9c9a043e54 100644
--- a/lld/test/ELF/aarch64-undefined-weak.s
+++ b/lld/test/ELF/aarch64-undefined-weak.s
@@ -1,7 +1,7 @@
 // REQUIRES: aarch64
 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t.o
 // RUN: ld.lld --image-base=0x10000000 %t.o -o %t
-// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+// RUN: llvm-objdump -d -z --no-show-raw-insn %t | FileCheck %s
 
 // Check that the ARM 64-bit ABI rules for undefined weak symbols are applied.
 // Branch instructions are resolved to the next instruction. Undefined
diff --git a/llvm/test/tools/llvm-objdump/ELF/AArch64/zeroes.test b/llvm/test/tools/llvm-objdump/ELF/AArch64/zeroes.test
new file mode 100644
index 00000000000000..a56d056f8a2256
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/ELF/AArch64/zeroes.test
@@ -0,0 +1,66 @@
+## Test zero dumping when a data mapping symbol is active.
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t
+# RUN: llvm-objdump -t -d %t | FileCheck %s
+
+# CHECK:      SYMBOL TABLE:
+# CHECK-NEXT: 0000000000000000 l       .text  0000000000000000 $d
+# CHECK-NEXT: 000000000000000c l       .text  0000000000000000 $x
+# CHECK-NEXT: 0000000000000010 l       .text  0000000000000000 $d
+
+# CHECK:      0000000000000000 <_start>:
+# CHECK-NEXT:                 ...
+# CHECK-NEXT:        8: 01 00 00 00   .word   0x00000001
+# CHECK-NEXT:        c: d503201f      nop
+# CHECK-NEXT:                 ...
+# CHECK-NEXT:       18: d503201f      nop
+# CHECK-NEXT:                 ...
+# CHECK-NEXT:       2c: d503201f      nop
+# CHECK-NEXT:                 ...
+# CHECK-NEXT:       48: d503201f      nop
+
+# RUN: llvm-objdump -d -z %t | FileCheck %s --check-prefix=ZERO
+
+# ZERO:      0000000000000000 <_start>:
+# ZERO-NEXT:        0: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:        4: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:        8: 01 00 00 00   .word   0x00000001
+# ZERO-NEXT:        c: d503201f      nop
+# ZERO-NEXT:       10: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:       14: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:       18: d503201f      nop
+
+## Check we do not skip zeroes blocks if have relocations pointed to these places.
+# RUN: llvm-objdump -d -r %t | FileCheck %s --check-prefix=RELOC
+
+# RELOC:      0000000000000000 <_start>:
+# RELOC-NEXT:                 ...
+# RELOC-NEXT:        8: 01 00 00 00   .word   0x00000001
+# RELOC-NEXT:        c: d503201f      nop
+# RELOC-NEXT:                 ...
+# RELOC-NEXT:       18: d503201f      nop
+# RELOC-NEXT:       1c: 00 00 00 00   .word   0x00000000
+# RELOC-NEXT:                 000000000000001c:  R_AARCH64_ABS64      x1
+# RELOC-NEXT:                 ...
+# RELOC-NEXT:       2c: d503201f      nop
+# RELOC-NEXT:                 ...
+# RELOC-NEXT:       38: 00 00 00 00   .word   0x00000000
+# RELOC-NEXT:                 0000000000000038:  R_AARCH64_ABS64      x2
+# RELOC-NEXT:                 ...
+# RELOC-NEXT:       48: d503201f      nop
+
+.globl _start
+_start:
+  .space 8
+  .long 1
+  nop
+  .space 8
+  nop
+
+  .quad x1
+  .space 8
+  nop
+
+  .space 8
+  .quad x2
+  .space 8
+  nop
diff --git a/llvm/test/tools/llvm-objdump/ELF/ARM/zeroes.test b/llvm/test/tools/llvm-objdump/ELF/ARM/zeroes.test
new file mode 100644
index 00000000000000..8601343bd146e9
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/ELF/ARM/zeroes.test
@@ -0,0 +1,47 @@
+## Test zero dumping when a data mapping symbol is active.
+# RUN: llvm-mc -filetype=obj -triple=armv7 %s -o %t
+# RUN: llvm-objdump -t -d %t | FileCheck %s
+
+# CHECK:      SYMBOL TABLE:
+# CHECK-NEXT: 00000000 l       .text  00000000 $d
+# CHECK-NEXT: 0000000c l       .text  00000000 $a
+# CHECK-NEXT: 00000010 l       .text  00000000 $d
+
+# CHECK:      00000000 <_start>:
+# CHECK-NEXT:                ...
+# CHECK-NEXT:       8: 01 00 00 00   .word   0x00000001
+# CHECK-NEXT:       c: e320f000      <unknown>
+# CHECK-NEXT:                ...
+# CHECK-NEXT:      18: e320f000      <unknown>
+# CHECK-NEXT:                ...
+# CHECK-NEXT:      28: e320f000      <unknown>
+# CHECK-NEXT:                ...
+# CHECK-NEXT:      40: e320f000      <unknown>
+
+# RUN: llvm-objdump -d -z --triple=armv7 %t | FileCheck %s --check-prefix=ZERO
+
+# ZERO:      00000000 <_start>:
+# ZERO-NEXT:       0: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:       4: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:       8: 01 00 00 00   .word   0x00000001
+# ZERO-NEXT:       c: e320f000      nop
+# ZERO-NEXT:      10: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:      14: 00 00 00 00   .word   0x00000000
+# ZERO-NEXT:      18: e320f000      nop
+
+.globl _start
+_start:
+  .space 8
+  .long 1
+  nop
+  .space 8
+  nop
+
+  .long x1
+  .space 8
+  nop
+
+  .space 8
+  .long x2
+  .space 8
+  nop
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index b69d14b4e7609a..8073c898b8a147 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2244,27 +2244,28 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
           return false;
         };
 
+        // When -z or --disassemble-zeroes are given we always dissasemble
+        // them. Otherwise we might want to skip zero bytes we see.
+        if (!DisassembleZeroes) {
+          uint64_t MaxOffset = End - Index;
+          // For --reloc: print zero blocks patched by relocations, so that
+          // relocations can be shown in the dump.
+          if (InlineRelocs && RelCur != RelEnd)
+            MaxOffset = std::min(RelCur->getOffset() - RelAdjustment - Index,
+                                 MaxOffset);
+
+          if (size_t N =
+                  countSkippableZeroBytes(Bytes.slice(Index, MaxOffset))) {
+            FOS << "\t\t..." << '\n';
+            Index += N;
+            continue;
+          }
+        }
+
         if (DumpARMELFData) {
           Size = dumpARMELFData(SectionAddr, Index, End, Obj, Bytes,
                                 MappingSymbols, *DT->SubtargetInfo, FOS);
         } else {
-          // When -z or --disassemble-zeroes are given we always dissasemble
-          // them. Otherwise we might want to skip zero bytes we see.
-          if (!DisassembleZeroes) {
-            uint64_t MaxOffset = End - Index;
-            // For --reloc: print zero blocks patched by relocations, so that
-            // relocations can be shown in the dump.
-            if (InlineRelocs && RelCur != RelEnd)
-              MaxOffset = std::min(RelCur->getOffset() - RelAdjustment - Index,
-                                   MaxOffset);
-
-            if (size_t N =
-                    countSkippableZeroBytes(Bytes.slice(Index, MaxOffset))) {
-              FOS << "\t\t..." << '\n';
-              Index += N;
-              continue;
-            }
-          }
 
           if (DumpTracebackTableForXCOFFFunction &&
               doesXCOFFTracebackTableBegin(Bytes.slice(Index, 4))) {

Copy link
Collaborator

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the change. From the build kite result looks like MC/ARM/ltorg-range.s will need to add -z.

arm-none-eabi-objdump and aarch64-none-elf-objdump use ellipsis for more than 4-bytes of zeroes.

I tend to use GNU objdump whenever I have a file with a non-trivial amount of zeroes so for me this is a big useability improvement.

May want to give jh7370 some time to review too.

@MaskRay MaskRay requested a review from jh7370 September 23, 2024 20:38
@MaskRay
Copy link
Member Author

MaskRay commented Sep 23, 2024

LGTM for the change. From the build kite result looks like MC/ARM/ltorg-range.s will need to add -z.

arm-none-eabi-objdump and aarch64-none-elf-objdump use ellipsis for more than 4-bytes of zeroes.

I tend to use GNU objdump whenever I have a file with a non-trivial amount of zeroes so for me this is a big useability improvement.

May want to give jh7370 some time to review too.

Thanks for the review. I hope this is useful to your lld patch for testing.

I recall that jh7370 mentioned vacation plan recently. Anyhow I'll hold off merging this for two days.

Created using spr 1.3.5-bogner
@llvmbot llvmbot added backend:ARM mc Machine (object) code labels Sep 25, 2024
@MaskRay MaskRay merged commit abe0dd1 into main Sep 25, 2024
7 of 9 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/llvm-objdump-print-even-if-a-data-mapping-symbol-is-active branch September 25, 2024 17:32
@tex3d
Copy link
Contributor

tex3d commented Sep 26, 2024

@MaskRay
It looks like this change broke two BOLT tests:

BOLT :: AArch64/constant_island_pie_update.s
BOLT :: AArch64/update-weak-reference-symbol.s

These are broken in this PR's checks, and subsequent builds from main since merging.

@MaskRay
Copy link
Member Author

MaskRay commented Sep 26, 2024

@MaskRay It looks like this change broke two BOLT tests:

BOLT :: AArch64/constant_island_pie_update.s
BOLT :: AArch64/update-weak-reference-symbol.s

These are broken in this PR's checks, and subsequent builds from main since merging.

Sorry but I'm not at a computer. You could fix the tests by adding -z to the llvm-objdump line

tex3d added a commit to tex3d/llvm-project that referenced this pull request Sep 26, 2024
llvm#109553 changed default llvm-objdump output for consecutive zeros.

This broke two tests:
BOLT :: AArch64/constant_island_pie_update.s
BOLT :: AArch64/update-weak-reference-symbol.s

This fixes the test failures by adding -z to llvm-objdump in RUN line.
@tex3d
Copy link
Contributor

tex3d commented Sep 26, 2024

@MaskRay
I created a PR (#110071), since I don't have write access. Someone who does can merge my PR.
I tested the fixes locally, and was able to repro those test failures, so I'm pretty sure the fix is good.

bob80905 pushed a commit that referenced this pull request Sep 26, 2024
abe0dd1 (#109553) changed default
llvm-objdump output for consecutive zeros.

This broke two tests:
BOLT :: AArch64/constant_island_pie_update.s
BOLT :: AArch64/update-weak-reference-symbol.s

This fixes the test failures by adding -z to llvm-objdump in RUN line.
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Sep 27, 2024
abe0dd1 (llvm#109553) changed default
llvm-objdump output for consecutive zeros.

This broke two tests:
BOLT :: AArch64/constant_island_pie_update.s
BOLT :: AArch64/update-weak-reference-symbol.s

This fixes the test failures by adding -z to llvm-objdump in RUN line.
Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm back - looks fine to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants