[ARM] : Mark debug sections of file containing cmse entry functions.

Message ID 4a9ab182-94f0-c149-4939-9087427a7184@arm.com
State New
Headers show
Series
  • [ARM] : Mark debug sections of file containing cmse entry functions.
Related show

Commit Message

Srinath Parvathaneni July 1, 2019, 3:45 p.m.
Hi All,

Consider a file containing only Armv8-M secure entry functions.
This file is compiled and linked with "-march=armv8-m.main -mfloat-abi=hard
-mfpu=fpv5-sp-d16 -mcmse -static --specs=rdimon.specs
-Wl,--section-start,.gnu.sgstubs=0x190000 -ffunction-sections 
-fdata-sections
-Wl,--gc-sections -g" options to generate an executable.

The executable generated does not contain any debug information of these 
secure entry
functions even though it contains secure entry functions in the .text 
section.

Example:
$ cat main.c
int main (void)
{
    return 0;
}

$ cat sec.c
void __attribute__((cmse_nonsecure_entry))
SecureLED_On ()
{
}

Generate the object files "main.o" and "sec.o" for above test, using 
below command.

1. $ arm-none-eabi-gcc -march=armv8-m.main -mfloat-abi=hard 
-mfpu=fpv5-sp-d16 -mcmse
-static --specs=rdimon.specs -ffunction-sections -fdata-sections main.c 
sec.c -g -c

Using linker, generate the executable for above generated object files.

2.$ arm-none-eabi-ld --section-start .gnu.sgstubs=0x190000 --gc-sections
main.o sec.o -e0 -o main_sec.out

Check for "SecureLED_On" in dwarf information generated for executable 
"main_sec.out".

3. $ arm-none-eabi-objdump --dwarf=info main_sec.out |grep "SecureLED_On"

There is no match for the function "SecureLED_On" in .dwarf_info.

After applying this patch and performing above steps 2 and 3, the output is:
       <8f>   DW_AT_name        : (indirect string, offset: 0x9d): 
SecureLED_On

This patch fixes the linker by marking all the debug sections (setting 
gc_mark to 1)
when .text section containing secure entry functions is marked.

Regression testsuite when run for arm-none-eabi shows no regression.

Ok for master? If ok, please commit on my behalf, I don't have the 
commit rights.

bfd/ChangeLog:

2019-07-01  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

	* elf32-arm.c (elf32_arm_gc_mark_extra_sections): Mark debug
	sections when .text section contain secure entry functions
	is marked.

ld/ChangeLog:

2019-07-01  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

	* testsuite/ld-arm/arm-elf.exp: Add tests.
	* testsuite/ld-arm/cmse_main.s: New test.
	* testsuite/ld-arm/cmse_main_sec_debug.d: Likewise.
	* testsuite/ld-arm/cmse_sec_debug.s: Likewise.

Comments

Nick Clifton July 2, 2019, 11:46 a.m. | #1
Hi Srinath,

> Ok for master? If ok, please commit on my behalf, I don't have the 

> commit rights.


Approved and applied.

Cheers
  Nick

> bfd/ChangeLog:

> 

> 2019-07-01  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

> 

> 	* elf32-arm.c (elf32_arm_gc_mark_extra_sections): Mark debug

> 	sections when .text section contain secure entry functions

> 	is marked.

> 

> ld/ChangeLog:

> 

> 2019-07-01  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

> 

> 	* testsuite/ld-arm/arm-elf.exp: Add tests.

> 	* testsuite/ld-arm/cmse_main.s: New test.

> 	* testsuite/ld-arm/cmse_main_sec_debug.d: Likewise.

> 	* testsuite/ld-arm/cmse_sec_debug.s: Likewise.

> 

>
Srinath Parvathaneni July 2, 2019, 12:26 p.m. | #2
Hi Nick,


> Approved and applied.


Thank you for the approval and commit.


Could you please backport this patch to 2.32 branch as well.


Regards,

SRI.

________________________________
From: Nick Clifton <nickc@redhat.com><mailto:nickc@redhat.com>

Sent: 02 July 2019 12:46:00
To: Srinath Parvathaneni; binutils
Cc: nd; Richard Earnshaw
Subject: Re: [PATCH][BINUTILS][ARM]: Mark debug sections of file containing cmse entry functions.

Hi Srinath,

> Ok for master? If ok, please commit on my behalf, I don't have the

> commit rights.


Approved and applied.

Cheers
  Nick

> bfd/ChangeLog:

>

> 2019-07-01  Srinath Parvathaneni  <srinath.parvathaneni@arm.com><mailto:srinath.parvathaneni@arm.com>

>

>        * elf32-arm.c (elf32_arm_gc_mark_extra_sections): Mark debug

>        sections when .text section contain secure entry functions

>        is marked.

>

> ld/ChangeLog:

>

> 2019-07-01  Srinath Parvathaneni  <srinath.parvathaneni@arm.com><mailto:srinath.parvathaneni@arm.com>

>

>        * testsuite/ld-arm/arm-elf.exp: Add tests.

>        * testsuite/ld-arm/cmse_main.s: New test.

>        * testsuite/ld-arm/cmse_main_sec_debug.d: Likewise.

>        * testsuite/ld-arm/cmse_sec_debug.s: Likewise.

>

>
Nick Clifton July 2, 2019, 1:52 p.m. | #3
Hi Sri,

> Could you please backport this patch to 2.32 branch as well.

Done.

Cheers
  Nick

Patch

diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 52fd48f6ec98f8c104498b2a461d2a622d6a909f..fc6b75f5bf75e06eaa39ab386e6fed0c31222e61 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -15903,6 +15903,8 @@  elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
   struct elf_link_hash_entry **sym_hashes;
   struct elf32_arm_link_hash_entry *cmse_hash;
   bfd_boolean again, is_v8m, first_bfd_browse = TRUE;
+  bfd_boolean debug_sec_need_to_be_marked = FALSE;
+  asection *isec;
 
   _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
 
@@ -15964,8 +15966,24 @@  elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
 		      if (!cmse_sec->gc_mark
 			  && !_bfd_elf_gc_mark (info, cmse_sec, gc_mark_hook))
 			return FALSE;
+		      /* The debug sections related to these secure entry
+			 functions are marked on enabling below flag.  */
+		      debug_sec_need_to_be_marked = TRUE;
 		    }
 		}
+	      if (debug_sec_need_to_be_marked)
+		{
+		  /* Looping over all the sections of the object file containing
+		     Armv8-M secure entry functions and marking all the debug
+		     sections.  */
+		  for (isec = sub->sections; isec != NULL; isec = isec->next)
+		    {
+		      /* If not a debug sections, skip it.  */
+		      if (!isec->gc_mark && (isec->flags & SEC_DEBUGGING))
+			isec->gc_mark = 1 ;
+		    }
+		  debug_sec_need_to_be_marked = FALSE;
+		}
 	    }
 	}
       first_bfd_browse = FALSE;
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index 7d3217f87a26303f776d2390cdab9a426ef3d3e9..72036785270a0ce79f314772737b57969b894fc9 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -787,6 +787,12 @@  set armeabitests_nonacl {
      {cmse-implib.s}
      {{ld cmse-new-wrong-implib.out}}
      "cmse-new-wrong-implib"}
+    {"Secure gateway veneers:cmse functions debug information missing"
+      "--section-start .gnu.sgstubs=0x190000 --gc-sections -e0" ""
+      "-march=armv8-m.main -mthumb"
+      {cmse_main.s cmse_sec_debug.s}
+      {{objdump --dwarf=info cmse_main_sec_debug.d}}
+      "cmse_main_sec_debug"}
 
     {"R_ARM_THM_JUMP19 Relocation veneers: Short"
      "--section-start destsect=0x000108002 --section-start .text=0x8000" ""
diff --git a/ld/testsuite/ld-arm/cmse_main.s b/ld/testsuite/ld-arm/cmse_main.s
new file mode 100644
index 0000000000000000000000000000000000000000..5047c02f46ebd0df0f211e8ee5c67e8a81e0d71b
--- /dev/null
+++ b/ld/testsuite/ld-arm/cmse_main.s
@@ -0,0 +1,21 @@ 
+	.arch armv8-m.main
+	.file	"cmse_main.c"
+	.text
+.Ltext0:
+	.cfi_sections	.debug_frame
+	.section	.text.main,"ax",%progbits
+	.align	1
+	.global	main
+	.arch armv8-m.main
+	.syntax unified
+	.thumb
+	.thumb_func
+	.fpu fpv5-sp-d16
+	.type	main, %function
+main:
+.LFB0:
+	.file 1 "cmse_main.c"
+	.loc 1 2 1
+	.cfi_startproc
+	.cfi_endproc
+.LFE0:
diff --git a/ld/testsuite/ld-arm/cmse_main_sec_debug.d b/ld/testsuite/ld-arm/cmse_main_sec_debug.d
new file mode 100644
index 0000000000000000000000000000000000000000..61280b769c146ac1005bc19f7c547cb797d4baa2
--- /dev/null
+++ b/ld/testsuite/ld-arm/cmse_main_sec_debug.d
@@ -0,0 +1,29 @@ 
+
+tmpdir/cmse_main_sec_debug:     .*
+
+Contents of the \.debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x34 \(32-bit\)
+   Version:       4
+   Abbrev Offset: 0x0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    <c>   DW_AT_producer    : \(indirect string, offset: 0x6\): GNU C17 10.0.0 20190617
+    <10>   DW_AT_language    : 12	\(ANSI C99\)
+    <11>   DW_AT_name        : \(indirect string, offset: 0x0\): sec.c
+    <15>   DW_AT_comp_dir    : \(indirect string, offset: 0x2b\): Blinky
+    <19>   DW_AT_ranges      : 0x0
+    <1d>   DW_AT_low_pc      : 0x0
+    <21>   DW_AT_stmt_list   : 0x0
+ <1><25>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <26>   DW_AT_external    : 1
+    <26>   DW_AT_name        : \(indirect string, offset: 0x1e\): SecureLED_On
+    <2a>   DW_AT_decl_file   : 1
+    <2b>   DW_AT_decl_line   : 2
+    <2c>   DW_AT_decl_column : 1
+    <2d>   DW_AT_low_pc      : 0x8000
+    <31>   DW_AT_high_pc     : 0xc
+    <35>   DW_AT_frame_base  : 1 byte block: 9c 	\(DW_OP_call_frame_cfa\)
+    <37>   DW_AT_GNU_all_call_sites: 1
+ <1><37>: Abbrev Number: 0
diff --git a/ld/testsuite/ld-arm/cmse_sec_debug.s b/ld/testsuite/ld-arm/cmse_sec_debug.s
new file mode 100644
index 0000000000000000000000000000000000000000..0ca949e3e5e7c23e556ecebf4b76ff4624dfa158
--- /dev/null
+++ b/ld/testsuite/ld-arm/cmse_sec_debug.s
@@ -0,0 +1,142 @@ 
+	.arch armv8-m.main
+	.file	"sec.c"
+	.text
+.Ltext0:
+	.cfi_sections	.debug_frame
+	.section	.text.SecureLED_On,"ax",%progbits
+	.align	1
+	.global	SecureLED_On
+	.global	__acle_se_SecureLED_On
+	.arch armv8-m.main
+	.syntax unified
+	.thumb
+	.thumb_func
+	.fpu fpv5-sp-d16
+	.type	__acle_se_SecureLED_On, %function
+	.syntax unified
+	.thumb
+	.thumb_func
+	.fpu fpv5-sp-d16
+	.type	SecureLED_On, %function
+SecureLED_On:
+__acle_se_SecureLED_On:
+.LFB0:
+	.file 1 "sec.c"
+	.loc 1 3 1
+	.cfi_startproc
+	push	{r7}
+	.cfi_def_cfa_offset 4
+	.cfi_offset 7, -4
+	add	r7, sp, #0
+	.cfi_def_cfa_register 7
+	.loc 1 4 1
+	mov	sp, r7
+	.cfi_def_cfa_register 13
+	ldr	r7, [sp], #4
+	.cfi_restore 7
+	.cfi_def_cfa_offset 0
+	bxns	lr
+	.cfi_endproc
+.LFE0:
+	.size	SecureLED_On, .-SecureLED_On
+	.text
+.Letext0:
+	.section	.debug_info,"",%progbits
+.Ldebug_info0:
+	.4byte	0x34
+	.2byte	0x4
+	.4byte	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.4byte	.LASF0
+	.byte	0xc
+	.4byte	.LASF1
+	.4byte	.LASF2
+	.4byte	.Ldebug_ranges0+0
+	.4byte	0
+	.4byte	.Ldebug_line0
+	.uleb128 0x2
+	.4byte	.LASF3
+	.byte	0x1
+	.byte	0x2
+	.byte	0x1
+	.4byte	.LFB0
+	.4byte	.LFE0-.LFB0
+	.uleb128 0x1
+	.byte	0x9c
+	.byte	0
+	.section	.debug_abbrev,"",%progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0xe
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0x1b
+	.uleb128 0xe
+	.uleb128 0x55
+	.uleb128 0x17
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x10
+	.uleb128 0x17
+	.byte	0
+	.byte	0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0
+	.uleb128 0x3f
+	.uleb128 0x19
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x6
+	.uleb128 0x40
+	.uleb128 0x18
+	.uleb128 0x2117
+	.uleb128 0x19
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_aranges,"",%progbits
+	.4byte	0x1c
+	.2byte	0x2
+	.4byte	.Ldebug_info0
+	.byte	0x4
+	.byte	0
+	.2byte	0
+	.2byte	0
+	.4byte	.LFB0
+	.4byte	.LFE0-.LFB0
+	.4byte	0
+	.4byte	0
+	.section	.debug_ranges,"",%progbits
+.Ldebug_ranges0:
+	.4byte	.LFB0
+	.4byte	.LFE0
+	.4byte	0
+	.4byte	0
+	.section	.debug_line,"",%progbits
+.Ldebug_line0:
+	.section	.debug_str,"MS",%progbits,1
+.LASF1:
+	.ascii	"sec.c\000"
+.LASF0:
+	.ascii	"GNU C17 10.0.0 20190617\000"
+.LASF3:
+	.ascii	"SecureLED_On\000"
+.LASF2:
+	.ascii	"Blinky\000"
+	.ident	"GCC: (GNU) 10.0.0 20190617 (experimental)"