Skip to content

Commit

Permalink
[ARM] Create mapping symbols with non-unique names
Browse files Browse the repository at this point in the history
Similar to llvm#99836 for AArch64.

Non-unique names save .strtab space and match GNU assembler.

Pull Request: llvm#99906

(cherry picked from commit 298a922)
  • Loading branch information
MaskRay authored and tru committed Jul 24, 2024
1 parent 411bb69 commit 7af27be
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 47 deletions.
8 changes: 4 additions & 4 deletions lld/test/ELF/arm-cmse-implib.s
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ secure_entry:
// CHECK1-NEXT: Num: Value Size Type Bind Vis Ndx Name
// CHECK1-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
// CHECK1-NEXT: 1: 00020000 0 NOTYPE LOCAL DEFAULT 2 $t
// CHECK1-NEXT: 2: 00008000 0 NOTYPE LOCAL DEFAULT 1 $t.0
// CHECK1-NEXT: 3: 00008004 0 NOTYPE LOCAL DEFAULT 1 $t.0
// CHECK1-NEXT: 2: 00008000 0 NOTYPE LOCAL DEFAULT 1 $t
// CHECK1-NEXT: 3: 00008004 0 NOTYPE LOCAL DEFAULT 1 $t
// CHECK1-NEXT: 4: 00008001 2 FUNC GLOBAL DEFAULT 1 secure_entry
// CHECK1-NEXT: 5: 00020001 8 FUNC GLOBAL DEFAULT 2 foo
// CHECK1-NEXT: 6: 00008005 2 FUNC GLOBAL DEFAULT 1 __acle_se_foo
Expand Down Expand Up @@ -82,8 +82,8 @@ secure_entry:
// CHECK2-NEXT: Num: Value Size Type Bind Vis Ndx Name
// CHECK2-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
// CHECK2-NEXT: 1: 00020000 0 NOTYPE LOCAL DEFAULT 2 $t
// CHECK2-NEXT: 2: 00008000 0 NOTYPE LOCAL DEFAULT 1 $t.0
// CHECK2-NEXT: 3: 00008004 0 NOTYPE LOCAL DEFAULT 1 $t.0
// CHECK2-NEXT: 2: 00008000 0 NOTYPE LOCAL DEFAULT 1 $t
// CHECK2-NEXT: 3: 00008004 0 NOTYPE LOCAL DEFAULT 1 $t
// CHECK2-NEXT: 4: 00008001 2 FUNC GLOBAL DEFAULT 1 secure_entry
// CHECK2-NEXT: 5: 00020011 8 FUNC WEAK DEFAULT 2 baz
// CHECK2-NEXT: 6: 00008005 2 FUNC GLOBAL DEFAULT 1 __acle_se_baz
Expand Down
8 changes: 2 additions & 6 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,15 @@ class ARMELFStreamer : public MCELFStreamer {
}

void EmitMappingSymbol(StringRef Name) {
auto *Symbol = cast<MCSymbolELF>(getContext().getOrCreateSymbol(
Name + "." + Twine(MappingSymbolCounter++)));
auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
emitLabel(Symbol);

Symbol->setType(ELF::STT_NOTYPE);
Symbol->setBinding(ELF::STB_LOCAL);
}

void emitMappingSymbol(StringRef Name, MCDataFragment &F, uint64_t Offset) {
auto *Symbol = cast<MCSymbolELF>(getContext().getOrCreateSymbol(
Name + "." + Twine(MappingSymbolCounter++)));
auto *Symbol = cast<MCSymbolELF>(getContext().createLocalSymbol(Name));
emitLabelAtPos(Symbol, SMLoc(), F, Offset);
Symbol->setType(ELF::STT_NOTYPE);
Symbol->setBinding(ELF::STB_LOCAL);
Expand Down Expand Up @@ -710,7 +708,6 @@ class ARMELFStreamer : public MCELFStreamer {

bool IsThumb;
bool IsAndroid;
int64_t MappingSymbolCounter = 0;

DenseMap<const MCSection *, std::unique_ptr<ElfMappingSymbolInfo>>
LastMappingSymbols;
Expand Down Expand Up @@ -1121,7 +1118,6 @@ void ARMELFStreamer::reset() {
MCTargetStreamer &TS = *getTargetStreamer();
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
ATS.reset();
MappingSymbolCounter = 0;
MCELFStreamer::reset();
LastMappingSymbols.clear();
LastEMSInfo.reset();
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/DebugInfo/Symbolize/ELF/arm-mapping-symbol.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

## Verify that mapping symbols are actually present in the object at expected
## addresses.
# RUN: llvm-nm --special-syms %t | FileCheck %s -check-prefix MAPPING_A
# RUN: llvm-nm --special-syms %t | FileCheck %s --check-prefix=MAPPING_A --match-full-lines

# MAPPING_A: 00000004 t $a.1
# MAPPING_A-NEXT: 00000000 t $d.0
# MAPPING_A-NEXT: 00000008 t $d.2
# MAPPING_A: 00000004 t $a
# MAPPING_A-NEXT: 00000000 t $d
# MAPPING_A-NEXT: 00000008 t $d
# MAPPING_A-NEXT: 00000000 T foo

# RUN: llvm-mc -filetype=obj -triple=thumbv7-none-linux %s -o %tthumb
# RUN: llvm-nm --special-syms %tthumb | FileCheck %s -check-prefix MAPPING_T
# RUN: llvm-nm --special-syms %tthumb | FileCheck %s --check-prefix=MAPPING_T --match-full-lines

# MAPPING_T: 00000000 t $d.0
# MAPPING_T-NEXT: 00000006 t $d.2
# MAPPING_T-NEXT: 00000004 t $t.1
# MAPPING_T: 00000000 t $d
# MAPPING_T-NEXT: 00000006 t $d
# MAPPING_T-NEXT: 00000004 t $t
# MAPPING_T-NEXT: 00000000 T foo

# RUN: llvm-symbolizer --obj=%t 4 8 | FileCheck %s -check-prefix SYMBOL
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/ARM/CheckDataSymbol.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RUN: llvm-mc -filetype=obj -assemble \
# RUN: -triple=arm-arm-none-eabi -mcpu=cortex-a9 %s -o - \
# RUN: | llvm-readobj -S --symbols - | FileCheck %s
# CHECK: Name: $d.1 ({{[1-9][0-9]+}})
# CHECK: Name: $d
# CHECK-NEXT: Value: 0x4
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Local (0x0)
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/ARM/data-in-code.ll
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exit:
;; TMB-NEXT: Section: [[MIXED_SECT:[^ ]+]]

;; TMB: Symbol {
;; TMB: Name: $d.1
;; TMB: Name: $d
;; TMB-NEXT: Value: 0x{{[0-9A-F]+}}
;; TMB-NEXT: Size: 0
;; TMB-NEXT: Binding: Local
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/MC/ARM/directive-arm-thumb-alignment.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
@ CHECK: Num: Value Size Type Bind Vis Ndx Name
@ CHECK-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
@ CHECK-NEXT: 1: 00000001 0 FUNC LOCAL DEFAULT 2 aligned_thumb
@ CHECK-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t.0
@ CHECK-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t
@ CHECK-NEXT: 3: 00000004 0 FUNC LOCAL DEFAULT 2 thumb_to_arm
@ CHECK-NEXT: 4: 00000004 0 NOTYPE LOCAL DEFAULT 2 $a.1
@ CHECK-NEXT: 5: 00000008 0 NOTYPE LOCAL DEFAULT 2 $d.2
@ CHECK-NEXT: 4: 00000004 0 NOTYPE LOCAL DEFAULT 2 $a
@ CHECK-NEXT: 5: 00000008 0 NOTYPE LOCAL DEFAULT 2 $d
@ CHECK-NEXT: 6: 0000000b 0 FUNC LOCAL DEFAULT 2 unaligned_arm_to_thumb
@ CHECK-NEXT: 7: 0000000a 0 NOTYPE LOCAL DEFAULT 2 $t.3
@ CHECK-NEXT: 7: 0000000a 0 NOTYPE LOCAL DEFAULT 2 $t

.thumb

Expand Down
12 changes: 6 additions & 6 deletions llvm/test/MC/ARM/multi-section-mapping.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@ RUN: llvm-mc -triple=armv7-linux-gnueabi -filetype=obj < %s | llvm-objdump -t - | FileCheck %s
@ RUN: llvm-mc -triple=armv7-linux-gnueabi -filetype=obj < %s | llvm-objdump -t - | FileCheck %s --match-full-lines

.text
add r0, r0, r0
Expand Down Expand Up @@ -42,10 +42,10 @@
@ + .starts_thumb to have $t at 0
@ + .starts_data to have $d at 0

@ CHECK: 00000000 l .text 00000000 $a.0
@ CHECK-NEXT: 00000000 l .wibble 00000000 $a.1
@ CHECK-NEXT: 00000000 l .starts_thumb 00000000 $t.2
@ CHECK-NEXT: 00000008 l .text 00000000 $t.3
@ CHECK-NEXT: 0000000a l .text 00000000 $d.4
@ CHECK: 00000000 l .text 00000000 $a
@ CHECK-NEXT: 00000000 l .wibble 00000000 $a
@ CHECK-NEXT: 00000000 l .starts_thumb 00000000 $t
@ CHECK-NEXT: 00000008 l .text 00000000 $t
@ CHECK-NEXT: 0000000a l .text 00000000 $d
@ CHECK-NOT: ${{[adt]}}

4 changes: 2 additions & 2 deletions llvm/test/MC/ARM/thumb-function-address.s
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ label:
@ CHECK-NEXT: 00000000 0 NOTYPE LOCAL DEFAULT UND
@ CHECK-NEXT: 00000001 0 FUNC LOCAL DEFAULT 2 func_label
@ CHECK-NEXT: 00000001 0 FUNC LOCAL DEFAULT 2 foo_impl
@ CHECK-NEXT: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t.0
@ CHECK-NEXT: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t
@ CHECK-NEXT: 00000003 0 FUNC LOCAL DEFAULT 2 foo_resolver
@ CHECK-NEXT: 00000003 0 IFUNC LOCAL DEFAULT 2 foo
@ CHECK-NEXT: 00000004 0 FUNC LOCAL DEFAULT 2 label
@ CHECK-NEXT: 00000008 0 NOTYPE LOCAL DEFAULT 2 $a.1
@ CHECK-NEXT: 00000008 0 NOTYPE LOCAL DEFAULT 2 $a
16 changes: 8 additions & 8 deletions llvm/test/MC/ARM/thumb-types.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
@ CHECK: Num: Value Size Type Bind Vis Ndx Name
@ CHECK-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
@ CHECK-NEXT: 1: 00000001 0 FUNC LOCAL DEFAULT 2 implicit_function
@ CHECK-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t.0
@ CHECK-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t
@ CHECK-NEXT: 3: 00000002 0 OBJECT LOCAL DEFAULT 2 implicit_data
@ CHECK-NEXT: 4: 00000002 0 NOTYPE LOCAL DEFAULT 2 $d.1
@ CHECK-NEXT: 4: 00000002 0 NOTYPE LOCAL DEFAULT 2 $d
@ CHECK-NEXT: 5: 00000008 0 FUNC LOCAL DEFAULT 2 arm_function
@ CHECK-NEXT: 6: 00000008 0 NOTYPE LOCAL DEFAULT 2 $a.2
@ CHECK-NEXT: 6: 00000008 0 NOTYPE LOCAL DEFAULT 2 $a
@ CHECK-NEXT: 7: 0000000c 0 NOTYPE LOCAL DEFAULT 2 untyped_text_label
@ CHECK-NEXT: 8: 0000000c 0 NOTYPE LOCAL DEFAULT 2 $t.3
@ CHECK-NEXT: 8: 0000000c 0 NOTYPE LOCAL DEFAULT 2 $t
@ CHECK-NEXT: 9: 0000000f 0 FUNC LOCAL DEFAULT 2 explicit_function
@ CHECK-NEXT: 10: 00000010 0 NOTYPE LOCAL DEFAULT 2 $d.4
@ CHECK-NEXT: 10: 00000010 0 NOTYPE LOCAL DEFAULT 2 $d
@ CHECK-NEXT: 11: 00000000 4 TLS LOCAL DEFAULT 5 tls
@ CHECK-NEXT: 12: 00000015 0 IFUNC LOCAL DEFAULT 2 indirect_function
@ CHECK-NEXT: 13: 00000014 0 NOTYPE LOCAL DEFAULT 2 $t.5
@ CHECK-NEXT: 13: 00000014 0 NOTYPE LOCAL DEFAULT 2 $t
@ CHECK-NEXT: 14: 00000000 0 NOTYPE LOCAL DEFAULT 4 untyped_data_label
@ CHECK-NEXT: 15: 00000000 0 NOTYPE LOCAL DEFAULT 4 $t.6
@ CHECK-NEXT: 15: 00000000 0 NOTYPE LOCAL DEFAULT 4 $t
@ CHECK-NEXT: 16: 00000002 0 OBJECT LOCAL DEFAULT 4 explicit_data
@ CHECK-NEXT: 17: 00000002 0 NOTYPE LOCAL DEFAULT 4 $d.7
@ CHECK-NEXT: 17: 00000002 0 NOTYPE LOCAL DEFAULT 4 $d


.syntax unified
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/ARM/thumb_set.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
@ CHECK: Num: Value Size Type Bind Vis Ndx Name
@ CHECK-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
@ CHECK-NEXT: 1: 00000000 0 FUNC LOCAL DEFAULT 2 arm_func
@ CHECK-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 $a.0
@ CHECK-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 $a
@ CHECK-NEXT: 3: 00000001 0 FUNC LOCAL DEFAULT 2 alias_arm_func
@ CHECK-NEXT: 4: 00000001 0 FUNC LOCAL DEFAULT 2 alias_arm_func2
@ CHECK-NEXT: 5: 00000001 0 FUNC LOCAL DEFAULT 2 alias_arm_func3
@ CHECK-NEXT: 6: 00000005 0 FUNC LOCAL DEFAULT 2 thumb_func
@ CHECK-NEXT: 7: 00000004 0 NOTYPE LOCAL DEFAULT 2 $t.1
@ CHECK-NEXT: 7: 00000004 0 NOTYPE LOCAL DEFAULT 2 $t
@ CHECK-NEXT: 8: 00000005 0 FUNC LOCAL DEFAULT 2 alias_thumb_func
@ CHECK-NEXT: 9: 5eed1e55 0 FUNC LOCAL DEFAULT ABS seedless
@ CHECK-NEXT: 10: e665a1ad 0 FUNC LOCAL DEFAULT ABS eggsalad
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/MC/ELF/ARM/execute-only-section.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ foo:


// CHECK: Section {
// CHECK: Name: .text (16)
// CHECK: Name: .text
// CHECK-NEXT: Type: SHT_PROGBITS (0x1)
// CHECK-NEXT: Flags [ (0x20000006)
// CHECK-NEXT: SHF_ALLOC (0x2)
Expand All @@ -29,7 +29,7 @@ foo:
// CHECK: }

// CHECK: Section {
// CHECK: Name: .text (16)
// CHECK: Name: .text
// CHECK-NEXT: Type: SHT_PROGBITS (0x1)
// CHECK-NEXT: Flags [ (0x20000006)
// CHECK-NEXT: SHF_ALLOC (0x2)
Expand All @@ -40,6 +40,6 @@ foo:
// CHECK: }

// CHECK: Symbol {
// CHECK: Name: foo (22)
// CHECK: Name: foo
// CHECK: Section: .text (0x3)
// CHECK: }
4 changes: 2 additions & 2 deletions llvm/test/tools/llvm-objdump/multiple-symbols.s
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

@ HEAD: Disassembly of section .text:
@ HEAD-EMPTY:
@ AMAP-NEXT: 00000000 <$a.0>:
@ AMAP-NEXT: 00000000 <$a>:
@ AAAA-NEXT: 00000000 <aaaa>:
@ BBBB-NEXT: 00000000 <bbbb>:
@ AABB-NEXT: 0: e0800080 add r0, r0, r0, lsl #1
@ AABB-NEXT: 4: e12fff1e bx lr
@ BOTH-EMPTY:
@ TMAP-NEXT: 00000008 <$t.1>:
@ TMAP-NEXT: 00000008 <$t>:
@ CCCC-NEXT: 00000008 <cccc>:
@ DDDD-NEXT: 00000008 <dddd>:
@ CCDD-NEXT: 8: eb00 0080 add.w r0, r0, r0, lsl #2
Expand Down

0 comments on commit 7af27be

Please sign in to comment.