Index: lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp =================================================================== --- lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -464,13 +464,20 @@ void emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes); void ChangeSection(MCSection *Section, const MCExpr *Subsection) override { - // We have to keep track of the mapping symbol state of any sections we - // use. Each one should start off as EMS_None, which is provided as the - // default constructor by DenseMap::lookup. LastMappingSymbols[getPreviousSection().first] = LastEMS; - LastEMS = LastMappingSymbols.lookup(Section); - MCELFStreamer::ChangeSection(Section, Subsection); + auto LastMappingSymbol = LastMappingSymbols.find(Section); + if (LastMappingSymbol != LastMappingSymbols.end()) { + LastEMS = LastMappingSymbol->second; + return; + } + // By default, the section is assigned EMS_Data. But if the section + // permissions specify that a section has executable instructions, the + // LastMappingSymbol defaults to None. + LastEMS = EMS_Data; + MCSectionELF *CurSection = cast(Section); + if (CurSection->UseCodeAlign()) + LastEMS = EMS_None; } /// This function is the one used to emit instruction data into the ELF @@ -627,7 +634,7 @@ int64_t MappingSymbolCounter = 0; DenseMap LastMappingSymbols; - ElfMappingSymbol LastEMS = EMS_None; + ElfMappingSymbol LastEMS = EMS_Data; // ARM Exception Handling Frame Information MCSymbol *ExTab; Index: test/MC/ARM/Inputs/1.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/1.s @@ -0,0 +1,3 @@ + .section .foobar,"ax",%progbits + nop + .word 32 Index: test/MC/ARM/Inputs/2.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/2.s @@ -0,0 +1,3 @@ + .section .foobar,"",%progbits + nop + .word 32 Index: test/MC/ARM/Inputs/3.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/3.s @@ -0,0 +1,3 @@ + .section .foobar,"aw",%progbits + nop + .word 32 Index: test/MC/ARM/Inputs/4.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/4.s @@ -0,0 +1,2 @@ + .section .foobar,"",%progbits + .word 32 Index: test/MC/ARM/Inputs/5.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/5.s @@ -0,0 +1,2 @@ + .section .foobar,"aw",%progbits + .word 32 Index: test/MC/ARM/Inputs/attr.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/attr.s @@ -0,0 +1,5 @@ + .text + .syntax unified + .eabi_attribute 67, "2.09" @ Tag_conformance + .cpu arm7tdmi + .eabi_attribute 6, 2 @ Tag_CPU_arch Index: test/MC/ARM/Inputs/ident.s =================================================================== --- /dev/null +++ test/MC/ARM/Inputs/ident.s @@ -0,0 +1 @@ + .ident "LLVM ARM Compiler" Index: test/MC/ARM/data-in-code.ll =================================================================== --- test/MC/ARM/data-in-code.ll +++ test/MC/ARM/data-in-code.ll @@ -60,23 +60,6 @@ ;; ARM-NEXT: Other: ;; ARM-NEXT: Section: [[MIXED_SECT]] -;; ARM: Symbol { -;; ARM: Name: $d -;; ARM-NEXT: Value: 0x0 -;; ARM-NEXT: Size: 0 -;; ARM-NEXT: Binding: Local (0x0) -;; ARM-NEXT: Type: None (0x0) -;; ARM-NEXT: Other: 0 -;; ARM-NEXT: Section: .ARM.exidx -;; ARM-NEXT: } - -;; ARM: Symbol { -;; ARM: Name: $d -;; ARM-NEXT: Value: 0 -;; ARM-NEXT: Size: 0 -;; ARM-NEXT: Binding: Local -;; ARM-NEXT: Type: None - ;; ARM-NOT: ${{[atd]}} ;; TMB: Symbol { Index: test/MC/ARM/mappingsymbols.s =================================================================== --- /dev/null +++ test/MC/ARM/mappingsymbols.s @@ -0,0 +1,33 @@ +# Check section containing code and data with permission executable for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/1.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s + +# Check section containing code and data with no permissions for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/2.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s + +# Check section containing code and data with read/write permissions for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/3.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s + +# Check section containing data with no permissions for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/4.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s -check-prefix=MAPPINGSYMBOLS + +# Check section containing only data with read/write permissions for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/5.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s -check-prefix=MAPPINGSYMBOLS + +# Check section containing the ident string with no permissions for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/ident.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s -check-prefix=MAPPINGSYMBOLS + +# Check section containing the attributes with no permissions for the section. +@ RUN: llvm-mc -triple armv7-none-linux -filetype=obj -o %t.o %p/Inputs/attr.s +@ RUN: llvm-readobj -elf-output-style=GNU -symbols %t.o | FileCheck %s -check-prefix=MAPPINGSYMBOLS + +#CHECK: $a +#CHECK: $d + +#MAPPINGSYMBOLS-NOT: $a +#MAPPINGSYMBOLS-NOT: $d Index: test/MC/ARM/multi-section-mapping.s =================================================================== --- test/MC/ARM/multi-section-mapping.s +++ test/MC/ARM/multi-section-mapping.s @@ -29,7 +29,6 @@ @ CHECK: 00000000 .text 00000000 $a @ CHECK-NEXT: 00000000 .wibble 00000000 $a -@ CHECK-NEXT: 00000000 .starts_data 00000000 $d @ CHECK-NEXT: 00000000 .starts_thumb 00000000 $t @ CHECK-NOT: ${{[adt]}} Index: test/Object/ARM/nm-mapping-symbol.s =================================================================== --- test/Object/ARM/nm-mapping-symbol.s +++ test/Object/ARM/nm-mapping-symbol.s @@ -7,5 +7,5 @@ // CHECK: Name: $d.0 // NM-NOT: $d.0 - .section .foobar,"",%progbits + .section .foobar,"ax",%progbits .asciz "foo"