Linker reference error for a too big array

Programming, for all ages and all languages.
Post Reply
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Linker reference error for a too big array

Post by Karlosoft »

I have a big array, 103680 bytes of 256 elements declared in the global scope. The linker is giving me a reference error at address .text+0x174 for this, because if a delete some items of the struct it works well. The reference error is very strange because it calls _memcpy a function not declared with the C calling conventions. My linker script is

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)


INPUT
(
	start.o
	main.o
	bA.o
	sys.o
	dbg.o
        ev.o
	mem.o
	drv.o
	lib.o
)

OUTPUT(Kernel.bin)



SECTIONS
{
	. = 0x100000;



	.text :
	{
		code = .;
		*(.text*)
		*(.gnu.linkonce.t*)
	}

	.rodata :
	{
		*(.rodata*)
		*(.gnu.linkonce.r*)
	}
	
	.data :
	{
		start_ctors = .;
		*(.ctor*)
		end_ctors = .;

		start_dtors = .;
		*(.dtor*)
		end_dtors = .;
	
		*(.data*)
		*(.gnu.linkonce.d*)
	}

	.bss :
	{
		bss = .;
		*(.COMMON*)
		*(.bss*)
		*(.gnu.linkonce.b*)
	}
	
	 /DISCARD/ :
	 {
		*(.comment)
		*(.eh_frame) 
	 }
	end = .;
}

EDIT: the problem isn't the array itself but the structure =.= How is it possible?

Code: Select all

struct console{
       uint8    id;         //The id of the console
       void    *appLink;    //The application which uses it
       uint32   session;    //The session id generated by the kernel
       uint8    active;
       
       //On direct video
       uint16   maxX;
       uint16   maxY;
       uint16   x;
       uint16   y;
       uint8    endLine;
       
       uint32   buffer;     //Memoryblock index   
       uint16   pages;
       
       //On buffer
       uint16   scrollY;    //Absolute
       uint16   topY; 
       
       //Color object
       union{
       uint8    color;
       struct{
       uint8    hcolor:4;
       uint8    lcolor:4;       
       };          
       };
       
       //Palette
       uint32 palette[16];

       void   (*cls)(); 
       void   (*refresh)();       
       void   (*put)(char ch);
       void   (*putpure)(char ch);
       char   (*getc)();
       wchar  (*getwc)();
       char   (*hgetc)();
       wchar  (*hgetwc)();
       void   (*refreshPalette)(uint32 *p);
       
       uint8   command[256];
       char   name[11];
       
       uint32 (*getCMD)();
       uint32 (*parser)();
       
};
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Linker reference error for a too big array

Post by Combuster »

Some basic sanity checks for builtins:
- are you using a cross-compiler?
- are you linking in libgcc?
If any of them are a "no", fix them.

I don't have the faulting code and corresponding annotated disassembly, but I'm guessing you are doing a non-pointer assignment (console x = array;) which causes gcc to inject a memcpy rather than some inline sequence above a certain data size.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Linker reference error for a too big array

Post by Karlosoft »

I'm using DJGPP on windows and I get 80x86 executable file.
I don't use libgcc, memcpy is defined in my code. The reference error is also shown if I remove all the references to System->memcpy (which points to the memcpy function itself).
Memcpy is never used in this object file.

if you need anything other or better explanations of what I did please ask me :)
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Linker reference error for a too big array

Post by Karlosoft »

_memcpy isn't declared like extern "C", this is why all my objects files reference it with a more complex name C++ linker style.
lib.o require the C reference only when that struct becomes too large, so I tried to declare memcpy like extern "C" and it is working =.=

I think I'll soon change compiler, mingw is good for windows? Aren't booth based on gcc?
Post Reply