Patchwork AMDHT misbehaves on recent compilers

login
register
about
Submitter Patrick Georgi
Date 2010-01-06 10:01:39
Message ID <4B445F83.40800@georgi-clan.de>
Download mbox | patch
Permalink /patch/735/
State Accepted
Commit r5001
Headers show

Comments

Patrick Georgi - 2010-01-06 10:01:39
Hi,

src/northbridge/amdht/ht_wrapper.c miscompiles on recent compilers
(gcc-4.4.1 in crossgcc for example). The compiler is correct in what it
does, our code isn't.

The issue is that with recent compilers swaplist is generated on the
stack, and then a pointer to that structure on stack is passed around.
The data is nearly immediately destroyed by subsequent calls.

The "const" modifier only makes the compiler ensure that no write
operations are made to the data, but says nothing about the life cycle.
To force the compiler to keep the array in read-only memory, it must be
global const or static const.

Thanks go to Myles for isolating the problem.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
ron minnich - 2010-01-06 10:03:39
arg, that kind of error is almost embarassing :-)

Acked-by: Ronald G. Minnich <rminnich@gmail.com>

ron

Patch

Index: src/northbridge/amd/amdht/ht_wrapper.c
===================================================================
--- src/northbridge/amd/amdht/ht_wrapper.c	(revision 4999)
+++ src/northbridge/amd/amdht/ht_wrapper.c	(working copy)
@@ -116,7 +116,7 @@ 
  */
 BOOL AMD_CB_ManualBUIDSwapList (u8 node, u16 link, u8 **List)
 {
-	const u8 swaplist[] = { 0xFF, CONFIG_HT_CHAIN_UNITID_BASE, CONFIG_HT_CHAIN_END_UNITID_BASE, 0xFF };
+	static const u8 swaplist[] = { 0xFF, CONFIG_HT_CHAIN_UNITID_BASE, CONFIG_HT_CHAIN_END_UNITID_BASE, 0xFF };
 	/* If the BUID was adjusted in early_ht we need to do the manual override */
 	if ((CONFIG_HT_CHAIN_UNITID_BASE != 0) && (CONFIG_HT_CHAIN_END_UNITID_BASE != 0)) {
 		printk_debug("AMD_CB_ManualBUIDSwapList()\n");