I have a C function as follows:
static uint32_t initrd_read(fs_node_t *node,
uint32_t offset, uint32_t size, uint8_t *buffer) {
initrd_file_header_t header = file_headers[node->inode];
if (offset > header.length)
return 0;
if (offset+size > header.length)
size = header.length-offset;
memcopy(buffer, header.offset+offset, size);
return size;
}
When linked with the rest of the program, an undefined reference to 'memcpy' is thrown. memcpy is never used in the code, and is not defined. The code is linked free-standing, so it is not conflicting with a C library. For some reason the linker thinks that the above function is calling memcpy at the beginning of the function call, and I’m not sure why.
Why could this be happening?
memcpycould be used implicitly by the compiler to perform “long” copying operations (like struct assignment). For example, in your code you are doingwhich looks like a good candidate for something that will actually be translated into an
memcpycall.Is there a reason you create a copy of that
initrd_file_header_tobject instead of accessing the original directly? I don’t see you modify that object, so you could just doand access the fields as
header->lengthetc. That probably will eliminate that implicit call tomemcpy.