Jump to content
  • 0

Undefined Reference to memcpy


Jason777
 Share

Question

This is really starting to piss me off... So I made a hack in C programming language (OOT Debug) for a custom item I'm making for a personal project. I'm finally near completion and I decide to try to compile the hack along with its hook. It seems that it can run through the compiler correctly, but when the object(s) pass into the linker the script fails to complete. Here's what happens when I run the makefile:

 

palacios@palacios-PC /c/n64tree-win32/Sword_of_Sages

$ make
../root/bin/mips64-gcc -fno-builtin -std=gnu99 -nodefaultlibs -march=vr4300 -mtu
ne=vr4300 -I../include -I.  -Os -mabi=32 -mno-gpopt   -c -o Sword_of_Sages.o Swo
rd_of_Sages.c
../root/bin/mips64-ld -o Sword_of_Sages.elf	 Sword_of_Sages.o -T Sword_of_Sag
es.x -L .
Sword_of_Sages.o: In function `_start':
Sword_of_Sages.c:(.text+0x50): undefined reference to `memcpy'
Sword_of_Sages.c:(.text+0x50): relocation truncated to fit: R_MIPS_26 against `m
emcpy'
make: *** [Sword_of_Sages.elf] Error 1

As far as I can tell, and I'm pretty damn confident, I made no such use of anything with the term "memcpy." Maybe it's a library? Perhaps, MinGW (GCC for windows) is making some unwanted optimizations? I suppose I could try checking .text section of the compiled object. Anyone who cares to help me, thanks.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

This is really starting to piss me off... So I made a hack in C programming language (OOT Debug) for a custom item I'm making for a personal project. I'm finally near completion and I decide to try to compile the hack along with its hook. It seems that it can run through the compiler correctly, but when the object(s) pass into the linker the script fails to complete. Here's what happens when I run the makefile:

 

palacios@palacios-PC /c/n64tree-win32/Sword_of_Sages

$ make
../root/bin/mips64-gcc -fno-builtin -std=gnu99 -nodefaultlibs -march=vr4300 -mtu
ne=vr4300 -I../include -I.  -Os -mabi=32 -mno-gpopt   -c -o Sword_of_Sages.o Swo
rd_of_Sages.c
../root/bin/mips64-ld -o Sword_of_Sages.elf	 Sword_of_Sages.o -T Sword_of_Sag
es.x -L .
Sword_of_Sages.o: In function `_start':
Sword_of_Sages.c:(.text+0x50): undefined reference to `memcpy'
Sword_of_Sages.c:(.text+0x50): relocation truncated to fit: R_MIPS_26 against `m
emcpy'
make: *** [sword_of_Sages.elf] Error 1

 

As far as I can tell, and I'm pretty damn confident, I made no such use of anything with the term "memcpy." Maybe it's a library? Perhaps, MinGW (GCC for windows) is making some unwanted optimizations? I suppose I could try checking .text section of the compiled object. Anyone who cares to help me, thanks.

 

memcpy is a C standard library function to copy a region of memory, you can find out more about it here:

http://lmgtfy.com/?q=memcpy

 

In your Sword_of_Sages.c file at 0x50, you have a reference to memcpy (it looks like you call it directly), but GCC doesn't have a copy of the C standard library compiled for MIPS as far as I know, so you won't have that available. You've also got "-nodefaultlibs" there, so...

Link to comment
Share on other sites

  • 0

Hmm.. I still have found no clues after a quite a bit of searching with google. I might as well post my Makefile:

#######################################
# Sword of Sages   --   OOT Debug ROM #
#######################################

# Sooner or later, I will need to integrate this into a ROM for the final patch of the Light Temple MOD

PROGRAM = Sword_of_Sages
PARTS   = $(PROGRAM).o

# Directories
N64BIN = ../root/bin

# Environment variables
CC	  = $(N64BIN)/mips64-gcc
LD	  = $(N64BIN)/mips64-ld
OBJCOPY = $(N64BIN)/mips64-objcopy
CHEAT   = $(N64BIN)/nemucheat
BINCODE = $(N64BIN)/bin2code

# Flags
LDFLAGS = -T $(PROGRAM).x -L .
CFLAGS  = -fno-builtin -std=gnu99 -nodefaultlibs -march=vr4300 -mtune=vr4300 
-I../include -I. $(NOBUILTIN) -Os  -mabi=32 -mno-gpopt

# CFLAGS Which use -fno-builtin and -nodefaultlibs
#CFLAGS  = -fno-builtin -std=gnu99 -nodefaultlibs -march=vr4300 -mtune=vr4300 
#   -I../include -I. $(NOBUILTIN) -Os  -mabi=32 -mno-gpopt

#CFLAGS seen in a shittload of spinout's code
#CFLAGS =  -G 0 -O3 --std=gnu99 -mtune=vr4300 -march=vr4300

# Compile binary
all: $(PROGRAM).bin
$(BINCODE) $(PROGRAM).bin 80600000 codes.txt
$(CHEAT) "Sword_of_Sages" 1 > final.txt

$(PROGRAM).bin: $(PROGRAM).elf
$(OBJCOPY) $(PROGRAM).elf $(PROGRAM).bin -O binary

$(PROGRAM).elf: $(PARTS)
$(LD) -o $(PROGRAM).elf $(PARTS) $(LDFLAGS)

clean:
rm *.o *.elf *~ *.bin final.txt -vf

EDIT:

While I'm at it, here's my (shitty) source code:

/**********************************
* Sword of Sages   --   OOT DEBUG *
**********************************/

#include <mips.h>

#define CURRENT_B_BUTTON_ITEM 0x8015E6C8
#define CURRENT_ANIMATION 0x80224764
#define CURRENT_LINK_XYZ 0x802245D4
#define CURRENT_TUNIC_RGB 0x802246FC

#define ACTOR_SPAWN_CNST 0x80213C44
#define GLOBAL_CONTEXT 0x80212020

/* Code Snippet borrowed from other people, mainly spinout and ZZT32 */

u16 ActorSpawn(u32 const_1, u32 const_2, u16 Actor, f32 fx, f32 fy, f32 fz, u16 rx, u16 ry, u16 rz, int Variable);

union FloatU32
{
f32 f;
u32 u;
};

typedef struct
{
union FloatU32 x;
union FloatU32 y;
union FloatU32 z;
} CoordU;

typedef struct
{ 
u32 something;
u32 some_RAM_pointer;
u32 ani_off;
u32 two[2];
f32 noFrames;
f32 current_f;
f32 speed;
} RAM_Animation; 

/* End of Code Snippet */ 

void _start (void) {
asm volatile("la $gp, _gp"); /* I saw this in every single one of Frauber's and (some of) ZZT's hacks... It seems to be necessary to "ensure that the data (ie, #define values, static variables, etc) will be loaded correctly" */


u8 *B_Button_Item = (void*)CURRENT_B_BUTTON_ITEM;
RAM_Animation *Link_Animation = (void*)CURRENT_ANIMATION;
CoordU *Link = (void*)CURRENT_LINK_XYZ;
u8 *Tunic_RGB = (void*)CURRENT_TUNIC_RGB;


u8 Valid_Sword = 0x7A;
u32 Valid_Animation[29] = {  /* Shielding and Defensive */
0x04002518, 0x04002520, 0x04002588, 

/* Slashing */
0x04002890, 0x04002898, 0x040028A0, 0x040028A8,
0x040028C0, 0x040028D0, 0x04002978, 0x04002A98, 
0x04002B48, 0x04002B50, 0x04002C70,  

/* Stabbing */
0x040024C8, 0x04002548, 0x04002560, 0x040028E0, 
0x04002908, 0x04002980, 0x04002B88, 0x04002B98, 

/* Jump Attack */
0x04002900, 0x04002A60, 0x04002AD0,

/* Spin Attack and Finisher */
0x04002940, 0x040029C0, 0x04002B28, 0x04002CD0 };


/* Check if the item on the B-Button is the Biggoron's Sword */
if (*B_Button_Item == Valid_Sword) {

/* Use a for loop to cycle through all the possible animations */
for (int Index = 0; Index < 29; Index++) {

/* If the current animation is equal to whatever element in the array that the "Valid_Animation" is equal to, it is a vaild animation */
if (Link_Animation->ani_off == Valid_Animation[Index]) {

/* Change tunic color to white */
*Tunic_RGB = 0x04;

/* Rotational values my change if I can find where Link's rotation is stored in the RAM*/ 
/* TODO: New animation -- Turn off Nayru's Love if running */

if (Index == 0 || Index == 1 || Index == 2) { 
/* SHIELDING : Spawn Nayru's Love */
ActorSpawn(ACTOR_SPAWN_CNST, GLOBAL_CONTEXT, 0x00F4, Link->x.u, Link->y.u, Link->z.u, 0, 0, 0, 0x0000);
}
if (Index == 22 || Index == 23 || Index == 24) {
/* JUMP ATTACK : Spawn and shoot an Ice Arrow */
ActorSpawn(ACTOR_SPAWN_CNST, GLOBAL_CONTEXT, 0x010B, Link->x.u, Link->y.u, Link->z.u, 0, 0, 0, 0x0000);
}
if (Index == 3 || Index == 4 || Index == 5 || Index == 6 || Index == 7 || Index == 8 || Index == 9 || Index == 10 || Index == 11 || Index == 12 || Index == 13) {
/* SLASH : Spawn and shoot a Fire Arrow */
ActorSpawn(ACTOR_SPAWN_CNST, GLOBAL_CONTEXT, 0x010A, Link->x.u, Link->y.u, Link->z.u, 0, 0, 0, 0x0000);
}
if (Index == 14 || Index == 15 || Index == 16 || Index == 17 || Index == 18 || Index == 19 || Index == 20 || Index == 21) {
/* STAB : Spawn and shoot a Light Arrow */
ActorSpawn(ACTOR_SPAWN_CNST, GLOBAL_CONTEXT, 0x010C, Link->x.u, Link->y.u, Link->z.u, 0, 0, 0, 0x0000);
}
if (Index == 25 || Index == 26 || Index == 27 || Index == 28) {
/* SPIN : Spawn Din's Fire */
ActorSpawn(ACTOR_SPAWN_CNST, GLOBAL_CONTEXT, 0x009F, Link->x.u, Link->y.u, Link->z.u, 0, 0, 0, 0x0000);
}
}

}
}

/* Inline MIPS ASM to jump to the return address */
asm volatile("jr $ra");
}

To tell you the truth, I'm not sure if I'm writing inline assembly in the correct fashion.

Edited by Jason777
Link to comment
Share on other sites

  • 0

A little late here, but I decided to look again at this hack. I ended up getting it to compile along with its hook and running on OoT.

 

After looking at these two pages, I figured out that most of the errors were with my makefile. Indeed, I had some pretty impractical and contridictory cflags... Truth is, I had no knowledge on how to construct a makefile and had created one after looking at other people's work and using reasoning skills.

 

http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html

 

By the way, the hack works somewhat but is far from what I imagined and a little buggy; not every attack with the Biggoron's sword runs the code or has the desired effect. Needless to say, I need to fix up the code ALOT.

Link to comment
Share on other sites

  • 0

A little late here, but I decided to look again at this hack. I ended up getting it to compile along with its hook and running on OoT.

 

After looking at these two pages, I figured out that most of the errors were with my makefile. Indeed, I had some pretty impractical and contridictory cflags... Truth is, I had no knowledge on how to construct a makefile and had created one after looking at other people's work and using reasoning skills.

 

http://gcc.gnu.org/o...Dialect-Options

http://gcc.gnu.org/o...PS-Options.html

 

By the way, the hack works somewhat but is far from what I imagined and a little buggy; not every attack with the Biggoron's sword runs the code or has the desired effect. Needless to say, I need to fix up the code ALOT.

 

What is your hack suppose to do?
Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.