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 <[email protected]>
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");
-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to