diff mbox series

[v4] Fix array-bound compilation warnings

Message ID 20220201115024.49455-1-abhishek@linux.ibm.com
State Accepted
Headers show
Series [v4] Fix array-bound compilation warnings | expand

Checks

Context Check Description
snowpatch_ozlabs/github-Docker_builds_and_checks fail 8 of 9 jobs failed.

Commit Message

Abhishek Singh Tomar Feb. 1, 2022, 11:50 a.m. UTC
Resolves : the warray bounds warning during compilation

/build/libc/include/string.h:34:16: warning: '__builtin_memset' offset [0, 2097151] is out of the bounds [0, 0] [-Warray-bounds]
34 | #define memset __builtin_memset
hw/fsp/fsp.c:1855:9: note: in expansion of macro 'memset'
1855 | memset(fsp_tce_table, 0, PSI_TCE_TABLE_SIZE);

use skiboot.lds.S to link constant address of pointer

Signed-off-by: Abhishek Singh Tomar <abhishek@linux.ibm.com>
---

Error:
 After patch merged compilation failed with error 
[LD]  skiboot.tmp.elf
powerpc64-linux-gnu-ld: Heap collision with image
make: *** [/home/abhishekTomar/project/sourceCode/opal/opalAbhishekRepo/skiboot/Makefile.main:345: skiboot.tmp.elf] Error 1

---
 core/console.c     |  4 ++--
 core/fast-reboot.c |  6 ++++--
 core/init.c        |  6 +++++-
 core/opal-dump.c   |  8 ++++----
 hdata/spira.c      |  4 +++-
 hw/fsp/fsp.c       |  4 ++--
 skiboot.lds.S      | 11 ++++++++++-
 7 files changed, 30 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/core/console.c b/core/console.c
index 2a150902..c91c7501 100644
--- a/core/console.c
+++ b/core/console.c
@@ -14,8 +14,8 @@ 
 #include <device.h>
 #include <processor.h>
 #include <cpu.h>
-
-static char *con_buf = (char *)INMEM_CON_START;
+extern char inmem_con_start[INMEM_CON_LEN];
+static char *con_buf = inmem_con_start;
 static size_t con_in;
 static size_t con_out;
 static bool con_wrapped;
diff --git a/core/fast-reboot.c b/core/fast-reboot.c
index fedfa88c..f3f3f5ad 100644
--- a/core/fast-reboot.c
+++ b/core/fast-reboot.c
@@ -303,6 +303,8 @@  static void cleanup_cpu_state(void)
 
 /* Entry from asm after a fast reset */
 void __noreturn fast_reboot_entry(void);
+extern char kernel_load_base[KERNEL_LOAD_SIZE];
+extern char initramfs_load_base[INITRAMFS_LOAD_SIZE];
 
 void __noreturn fast_reboot_entry(void)
 {
@@ -425,8 +427,8 @@  void __noreturn fast_reboot_entry(void)
 		 * Mambo may have embedded payload here, so don't clear
 		 * it at all.
 		 */
-		memset(KERNEL_LOAD_BASE, 0, KERNEL_LOAD_SIZE);
-		memset(INITRAMFS_LOAD_BASE, 0, INITRAMFS_LOAD_SIZE);
+		memset(kernel_load_base, 0, KERNEL_LOAD_SIZE);
+		memset(initramfs_load_base, 0, INITRAMFS_LOAD_SIZE);
 	}
 
 	/* Start preloading kernel and ramdisk */
diff --git a/core/init.c b/core/init.c
index b4d33518..c2bbc88e 100644
--- a/core/init.c
+++ b/core/init.c
@@ -869,7 +869,11 @@  void copy_exception_vectors(void)
 	 * this is the boot flag used by CPUs still potentially entering
 	 * skiboot.
 	 */
-	memcpy((void *)0x100, (void *)(SKIBOOT_BASE + 0x100),
+
+	extern char exception_vectors_start_addr[EXCEPTION_VECTORS_END - 0x100];
+	extern char copy_exceptio_vector_dst[EXCEPTION_VECTORS_END - 0x100];
+
+	memcpy(copy_exceptio_vector_dst, exception_vectors_start_addr,
 			EXCEPTION_VECTORS_END - 0x100);
 	sync_icache();
 }
diff --git a/core/opal-dump.c b/core/opal-dump.c
index 4f54a3ef..2aab9474 100644
--- a/core/opal-dump.c
+++ b/core/opal-dump.c
@@ -301,7 +301,7 @@  static int64_t opal_mpipl_update(enum opal_mpipl_ops ops,
 				 u64 src, u64 dest, u64 size)
 {
 	int rc;
-
+	extern char mdrt_table_base_addr[MDRT_TABLE_SIZE];
 	switch (ops) {
 	case OPAL_MPIPL_ADD_RANGE:
 		rc = payload_mpipl_register(src, dest, size);
@@ -330,7 +330,7 @@  static int64_t opal_mpipl_update(enum opal_mpipl_ops ops,
 		free(opal_mpipl_cpu_data);
 		opal_mpipl_cpu_data = NULL;
 		/* Clear MDRT table */
-		memset((void *)MDRT_TABLE_BASE, 0, MDRT_TABLE_SIZE);
+		memset(mdrt_table_base_addr, 0, MDRT_TABLE_SIZE);
 		/* Set MDRT count to max allocated count */
 		ntuple_mdrt->act_cnt = cpu_to_be16(MDRT_TABLE_SIZE / sizeof(struct mdrt_table));
 		rc = OPAL_SUCCESS;
@@ -529,8 +529,8 @@  bool is_mpipl_enabled(void)
 
 void opal_mpipl_init(void)
 {
-	void *mdst_base = (void *)MDST_TABLE_BASE;
-	void *mddt_base = (void *)MDDT_TABLE_BASE;
+	extern char mdst_base[MDST_TABLE_SIZE];
+	extern char mddt_base[MDDT_TABLE_SIZE];
 	struct dt_node *dump_node;
 
 	dump_node = dt_find_by_path(opal_node, "dump");
diff --git a/hdata/spira.c b/hdata/spira.c
index 1a351462..de2eed66 100644
--- a/hdata/spira.c
+++ b/hdata/spira.c
@@ -1784,7 +1784,9 @@  static void add_npus(void)
 static void fixup_spira(void)
 {
 #if !defined(TEST)
-	spiras = (struct spiras *)SPIRA_HEAP_BASE;
+	extern char spira_heap_base[SPIRA_HEAP_SIZE];
+
+	spiras = (struct spiras *) spira_heap_base;
 #endif
 
 	/* Validate SPIRA-S signature */
diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c
index 2c5f9d71..b4ac7765 100644
--- a/hw/fsp/fsp.c
+++ b/hw/fsp/fsp.c
@@ -91,7 +91,7 @@  static enum ipl_state ipl_state = ipl_initial;
 static struct fsp *first_fsp;
 static struct fsp *active_fsp;
 static u16 fsp_curseq = 0x8000;
-static __be64 *fsp_tce_table;
+static __be64 fsp_tce_table[PSI_TCE_TABLE_SIZE/sizeof(__be64)];
 
 #define FSP_INBOUND_SIZE	0x00100000UL
 static void *fsp_inbound_buf = NULL;
@@ -1850,7 +1850,7 @@  static int fsp_init_mbox(struct fsp *fsp)
 /* We use a single fixed TCE table for all PSI interfaces */
 static void fsp_init_tce_table(void)
 {
-	fsp_tce_table = (__be64 *)PSI_TCE_TABLE_BASE;
+//	fsp_tce_table = (__be64 *)PSI_TCE_TABLE_BASE;
 
 	memset(fsp_tce_table, 0, PSI_TCE_TABLE_SIZE);
 }
diff --git a/skiboot.lds.S b/skiboot.lds.S
index 058848fa..a982df31 100644
--- a/skiboot.lds.S
+++ b/skiboot.lds.S
@@ -250,7 +250,16 @@  SECTIONS
 	}
 
 	DEBUG_SECTIONS
-
+	kernel_load_base = 0x20000000;
+	initramfs_load_base =0x20000000 + 0x08000000;
+	inmem_con_start = INMEM_CON_START;
+	exception_vectors_start_addr = (SKIBOOT_BASE + 0x100);
+	mdrt_table_base_addr = MDRT_TABLE_BASE;
+	mdst_base = (SKIBOOT_BASE + MDST_TABLE_OFF);
+	mddt_base =  (SKIBOOT_BASE + MDDT_TABLE_OFF);
+	fsp_tce_table	= PSI_TCE_TABLE_BASE;
+	spira_heap_base = SPIRA_HEAP_BASE;
+	copy_exceptio_vector_dst = 0x100;
 	/* Discards */
 	/DISCARD/ : {
 		*(.note.GNU-stack)