#2528 assigned defect

Update https://devel.rtems.org/wiki/TBR/Delete/NewlibMemoryAllocation

Reported by: Nick Withers Owned by: Needs Funding
Priority: normal Milestone: Indefinite
Component: tool/newlib Version: 4.11
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

This'll require a re-audit of Newlib code.

Ideally, it would also detail where dynamic memory allocation is used in RTEMS code, too, and give an indication of whether it's initialisation-time only

Change History (18)

comment:1 Changed on Jan 15, 2016 at 8:28:11 AM by Nick Withers

Owner: set to Nick Withers
Status: newaccepted

I plan to do this next week, as it may be too much for a GCI task

comment:2 Changed on Jan 15, 2016 at 3:55:52 PM by Gedare Bloom

You could put together GCI tasks to audit the existing ones at least. You should consider relocating the wiki page to somewhere else. I'm not sure where.

comment:3 Changed on Jan 17, 2016 at 1:25:54 AM by Nick Withers

How does https://codein.withgoogle.com/dashboard/tasks/5374361066274816/preview/ look?

It only attempts to have students find occurrences, not actually audit them (e.g., can they be avoided), which might be too hard and too much work (to do them all, anyway)

comment:4 Changed on Jan 17, 2016 at 3:37:13 PM by Gedare Bloom

Do you expect one student to complete the entire task? Or should the task be subdivided?

Add "Research/Outreach" task type too.

You might want to fill in one row of each table as an example, and give a little more instruction about what should go into each column that the student is expected to fill in.

Last edited on Jan 17, 2016 at 3:37:23 PM by Gedare Bloom (previous) (diff)

comment:5 Changed on Jan 18, 2016 at 7:37:27 AM by Nick Withers

Righto, cheers.

Do you expect one student to complete the entire task? Or should the task be subdivided?

Yeah, I think it should be subdivided, especially as I've now added e.g., posix_memalign() to the list. Would you mind if I do that after we're happy with everything else, though?

Also, should it only be for newlib/libc/ and below (e.g., excluding libgloss)?

comment:6 Changed on Jan 18, 2016 at 12:52:30 PM by Gedare Bloom

Exclude libgloss. AFAIK we don't use anything from it...

comment:7 Changed on Jan 19, 2016 at 1:09:52 AM by Nick Withers

Righto, updated to specifically limit it to the newlib/libc directory.

I'm now thinking it might be better not to split it, as there's likely to be a disproportionate workload for e.g., each of the three tables...?

Last edited on Jan 19, 2016 at 1:10:14 AM by Nick Withers (previous) (diff)

comment:8 Changed on Jan 19, 2016 at 2:01:31 AM by Gedare Bloom

Yeah just post 1 task and see if anyone takes it. There's only 1 week or so left in the contest anyway.

comment:9 Changed on Jan 19, 2016 at 2:05:29 AM by Nick Withers

If you're happy with it, feel free to publish; I don't think I can

comment:10 Changed on Jan 25, 2016 at 5:52:32 AM by Nick Withers

Time has now passed for GCI students to pick up new tasks and unfortunately this one hasn't been selected.

I'll get onto it this week or next

comment:11 Changed on Feb 2, 2016 at 2:20:20 AM by Nick Withers

I think I've underestimated the work involved in producing a useful breakdown in a maintainable and error-free way, here.

Whilst I could just produce a list of files, line numbers and functions directly calling e.g., malloc(), I don't think that's very useful... What I'd like to know, as an application developer, is what functions I might call from my application that might result in memory allocation attempts. A simple grep's going to turn up lots of implementation detail (e.g., file-static functions that call malloc(), whereas I'd want instead the functions that are exposed to RTEMS applications that might call it).

Add in function pointers (e.g., ucs_2_init() in iconv/ces/ucs-2.c is pointed to by _iconv_to_ucs_ces_handlers_ucs_2.init, the latter struct then gets indexed by string in iconv_to_ucs_ces_t _iconv_to_ucs_ces), and a bunch 'o #defines and... my brain hurts.

Can anyone suggest tools which might help here? Otherwise we should perhaps just delete the article...

comment:12 Changed on Feb 2, 2016 at 4:11:18 AM by Joel Sherrill

http://www.gnu.org/software/cflow/ or a similar tool might be helpful.

But this also might be a good discussion to move to newlib's mailing list. What we really want is to know which public API calls can result in memory allocation.

comment:13 Changed on Feb 2, 2016 at 4:31:11 AM by Nick Withers

I don't think cflow (or cscope) can handle e.g., calls through function pointers.

But this also might be a good discussion to move to newlib's mailing list. What we really want is to know which public API calls can result in memory allocation

Agreed, and well put. Ideally they'd maintain that information and insist it were updated when commits change the situation

comment:14 Changed on Feb 3, 2016 at 12:52:45 PM by Gedare Bloom

Dealing with function pointers is hard. I did something before http://gedare-csphd.blogspot.com/2013/05/whos-calling-me-visualizing-function.html but again it did not follow dynamic code flow. For that you need something that can process a trace. There may also be some tools in the clang/llvm project that can generate similar.

comment:15 Changed on Feb 4, 2016 at 7:17:53 AM by Sebastian Huber

One approach would be to use the linker to resolve the dependencies. For example build a BSP with --enable-tests and use a test without references to malloc() etc.

sparc-rtems4.12-gcc -B../../../../../sis/lib/ -specs bsp_specs -qrtems -mcpu=cypress -O2 -g -ffunction-sections -fdata-sections -Wall -Wmissing-prototypes -Wimplicit-function-declaration -Wstrict-prototypes -Wnested-externs -Wl,-Map,map.txt -Wl,--gc-sections -mcpu=cypress -o spinternalerror01.exe init.o -Wl,-u,strftime

nm *.exe | grep '\<malloc\>\|\<calloc\>\|\<realloc\>'
0200b394 T malloc
0200b774 T realloc

comment:16 Changed on Feb 11, 2016 at 1:54:41 AM by Nick Withers

Owner: Nick Withers deleted
Status: acceptednew

Thanks for your Newlib mailing list post, Joel (https://sourceware.org/ml/newlib/2016/msg00052.html)!

It doesn't seem to have attracted any attention yet, unfortunately.

comment:17 Changed on Jan 26, 2017 at 7:16:00 AM by Sebastian Huber

Milestone: 4.11.14.11.2

comment:18 Changed on Feb 15, 2017 at 1:37:51 PM by Sebastian Huber

Milestone: 4.11.2Indefinite
Owner: set to Needs Funding
Status: newassigned
Note: See TracTickets for help on using tickets.