summaryrefslogtreecommitdiffstats
path: root/debian/patches/gcc12_build_dangling_pointer.patch
blob: 78bbacb87c9740e227de58ce4beda4a88ef51d0e (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
Borrowed and tweaked fix from:

commit be8eb0eed69f8bc9ac20837eae58e55218011880
Author: Michael Chang <mchang@suse.com>
Date:   Mon Mar 28 15:00:52 2022 +0800

    util/mkimage: Fix dangling pointer may be used error

diff --git a/util/mkimage.c b/util/mkimage.c
index a26cf76f7..58c199f7c 100644
--- a/util/mkimage	2022-12-11 15:41:56.717934782 +0000
+++ b/util/mkimage.c	2022-12-11 15:43:05.318432532 +0000
@@ -1383,6 +1383,10 @@
 	    section = (struct grub_pe32_section_table *)(o64 + 1);
 	  }
 
+#if __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer"
+#endif
 	PE_OHDR (o32, o64, header_size) = grub_host_to_target32 (header_size);
 	PE_OHDR (o32, o64, entry_addr) = grub_host_to_target32 (layout.start_address);
 	PE_OHDR (o32, o64, image_base) = 0;
@@ -1402,6 +1406,9 @@
 	/* The sections.  */
 	PE_OHDR (o32, o64, code_base) = grub_host_to_target32 (vma);
 	PE_OHDR (o32, o64, code_size) = grub_host_to_target32 (layout.exec_size);
+#if __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif
 	section = init_pe_section (image_target, section, ".text",
 				   &vma, layout.exec_size,
 				   image_target->section_align,
@@ -1413,10 +1420,17 @@
 	raw_size = layout.kernel_size - layout.exec_size;
 	scn_size = ALIGN_UP (raw_size, GRUB_PE32_FILE_ALIGNMENT);
 	/* ALIGN_UP (sbat_size, GRUB_PE32_FILE_ALIGNMENT) is done earlier. */
+#if __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer"
+#endif
 	PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (scn_size + sbat_size +
 							       ALIGN_UP (total_module_size,
 									 GRUB_PE32_FILE_ALIGNMENT));
 
+#if __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif
 	section = init_pe_section (image_target, section, ".data",
 				   &vma, scn_size, image_target->section_align,
 				   &raw_data, raw_size,
@@ -1448,8 +1462,15 @@
 	  }
 
 	scn_size = ALIGN_UP (layout.reloc_size, GRUB_PE32_FILE_ALIGNMENT);
+#if __GNUC__ >= 12
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer"
+#endif
 	PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (vma);
 	PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (scn_size);
+#if __GNUC__ >= 12
+#pragma GCC diagnostic pop
+#endif
 	memcpy (pe_img + raw_data, layout.reloc_section, scn_size);
 	init_pe_section (image_target, section, ".reloc",
 			 &vma, scn_size, image_target->section_align,