Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:55:42+00:00 2026-06-15T13:55:42+00:00

I need your help in this. I have an average knowledge of C and

  • 0

I need your help in this. I have an average knowledge of C and here is the problem. I am about to use some benchmarks to test some computer architecture stuff (branch misses, cache misses) on a new processor. The thing about it is that benchmarks are in C but I must not include any library calls. For example, I cannot use malloc because I am getting the error

"undefined reference to malloc" 

even if I have included the library. So I have to write my own malloc. I do not want it to be super efficient – just do the basics. As I am thinking it I must have an address in memory and everytime a malloc happens, I return a pointer to that address and increment the counter by that size. Malloc happens twice in my program so I do not even need large memory.

Can you help me on that? I have designed a Verilog and do not have so much experience in C.

I have seen previous answers but all seem too complicated for me. Besides, I do not have access to K-R book.

Cheers!

EDIT: maybe this can help you more:
I am not using gcc but the sde-gcc compiler. Does it make any difference? Maybe that’s why I am getting an undefined reference to malloc?

EDIT2:
I am testing a MIPS architecture:

I have included:

#include <stdlib.h>

and the errors are:

undefined reference to malloc
relocation truncated to fit: R_MIPS_26 against malloc

and the compiler command id:

test.o: test.c cap.h
sde-gcc -c -o test.s test.c -EB -march=mips64 -mabi=64 -G -O -ggdb -O2 -S
    sde-as -o test.o test.s EB -march=mips64 -mabi=64 -G -O -ggdb
    as_objects:=test.o init.o

EDIT 3:
ok, I used implementation above and it runs without any problems. The problem is that when doing embedded programming, you just have to define everything you are using so I defined my own malloc. sde-gcc didn’t recognize the malloc function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:55:43+00:00Added an answer on June 15, 2026 at 1:55 pm

    This is a very simple approach, which may get you past your 2 mallocs:

    static unsigned char our_memory[1024 * 1024]; //reserve 1 MB for malloc
    static size_t next_index = 0;
    
    void *malloc(size_t sz)
    {
        void *mem;
    
        if(sizeof our_memory - next_index < sz)
            return NULL;
    
        mem = &our_memory[next_index];
        next_index += sz;
        return mem;
    }
    
    void free(void *mem)
    {
       //we cheat, and don't free anything.
    }
    

    If required, you might need to align the memory piece you hand back, so e.g. you always
    give back memory addresses that’s on an address that’s a multiple of 4, 8, 16 or whatever you require.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem here and I need your help. Im trying to retrieve
ive being trying to cope with this problem but still. I need your help.
I need your help please. I have this xml file which I need to
I need your help to understand this better. This is my case. I have
I need your help in this case: I have: 1 11 111 Cat1 a,b,c
i need again your help... I have this php code: <? if(isset($_POST['addnews'])){ $type =
I need your help in my code I have problem when new div inserted
i need your help about this issue badly. i am trying to model a
I have a problem with my UPDATE functions and I need your help. I
i need your help in access db i have a table like this ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.