summaryrefslogtreecommitdiffstats
path: root/meta-microblaze/recipes-devtools/gcc/gcc-12/0014-Patch-microblaze-Add-INIT_PRIORITY-support-Added.patch
blob: 472c543c55fb2e6673ae4310b2ee83e77ab81dd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
From 30aa7cef2dd076637155384fba539838ddaf0163 Mon Sep 17 00:00:00 2001
From: Mahesh Bodapati <mbodapat@xilinx.com>
Date: Mon, 12 Sep 2022 20:20:00 +0530
Subject: [PATCH 14/53] [Patch, microblaze]: Add INIT_PRIORITY support Added 
 TARGET_ASM_CONSTRUCTOR and TARGET_ASM_DESTRUCTOR macros.

These macros allows users to control the order of initialization
of objects defined at namespace scope with the init_priority
attribute by specifying a relative priority, a constant integral
expression currently bounded between 101 and 65535 inclusive.

Lower numbers indicate a higher priority.
Upstream-Status: Pending

Signed-off-by: Mark Hatle <mark.hatle@amd.com>

---
 gcc/config/microblaze/microblaze.cc | 53 +++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/gcc/config/microblaze/microblaze.cc b/gcc/config/microblaze/microblaze.cc
index 6922dd94af7..4b0621db168 100644
--- a/gcc/config/microblaze/microblaze.cc
+++ b/gcc/config/microblaze/microblaze.cc
@@ -2635,6 +2635,53 @@ print_operand_address (FILE * file, rtx addr)
     }
 }
 
+/* Output an element in the table of global constructors. */
+void
+microblaze_asm_constructor (rtx symbol ATTRIBUTE_UNUSED, int priority)
+{
+    const char *section = ".ctors";
+    char buf[16];
+
+    if (priority != DEFAULT_INIT_PRIORITY)
+      {
+      sprintf (buf, ".ctors.%.5u",
+      /* Invert the numbering so the linker puts us in the proper
+      order; constructors are run from right to left, and the
+      linker sorts in increasing order.  */
+      MAX_INIT_PRIORITY - priority);
+      section = buf;
+      }
+
+    switch_to_section (get_section (section, 0, NULL));
+    assemble_align (POINTER_SIZE);
+    fputs ("\t.word\t", asm_out_file);
+    output_addr_const (asm_out_file, symbol);
+    fputs ("\n", asm_out_file);
+}
+
+/* Output an element in the table of global destructors. */
+void
+microblaze_asm_destructor (rtx symbol, int priority)
+{
+    const char *section = ".dtors";
+    char buf[16];
+    if (priority != DEFAULT_INIT_PRIORITY)
+      {
+      sprintf (buf, ".dtors.%.5u",
+      /* Invert the numbering so the linker puts us in the proper
+      order; constructors are run from right to left, and the
+      linker sorts in increasing order.  */
+      MAX_INIT_PRIORITY - priority);
+      section = buf;
+      }
+
+    switch_to_section (get_section (section, 0, NULL));
+    assemble_align (POINTER_SIZE);
+    fputs ("\t.word\t", asm_out_file);
+    output_addr_const (asm_out_file, symbol);
+    fputs ("\n", asm_out_file);
+}
+
 /* Emit either a label, .comm, or .lcomm directive, and mark that the symbol
    is used, so that we don't emit an .extern for it in 
    microblaze_asm_file_end.  */
@@ -3976,6 +4023,12 @@ microblaze_starting_frame_offset (void)
 #undef TARGET_ATTRIBUTE_TABLE
 #define TARGET_ATTRIBUTE_TABLE          microblaze_attribute_table
 
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR          microblaze_asm_constructor
+
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR           microblaze_asm_destructor
+
 #undef TARGET_IN_SMALL_DATA_P
 #define TARGET_IN_SMALL_DATA_P          microblaze_elf_in_small_data_p
 
-- 
2.37.1 (Apple Git-137.1)