You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server
0
b/PC, Mac & Vintage Computers publicado por u/Hayleia June 22, 2016, 04:17:20 PM
No idea if that's the right place to post, especially since I'm mostly asking for 3DS dev but since it might apply to C in general, I posted here...

So, is there a way to detect what functions are never called from a certain starting function, recursively?
Example, if you didn't get what I said.

int a() {
    return 1;
}
int b() {
    return 2;
}
int c() {
    return a()+1;
}
int main() {
  return c()+2;
}

Well, then.
- what functions aren't called from a? b, c, main.
- what functions aren't called from b? a, c, main.
- what functions aren't called from c? b, main (a is called directly from c).
- what functions aren't called from main? b (c is called directly from main and a is called indirectly from c).

So is there something that can parse my files and tell me this?
Note, this has to be a tool that happens before execution since, as I said, this is going to be executed from the 3DS, so I can't really run the compiled executable through some IDE tool that sends stuff to GDB or whatever, that won't work.
Inicia sesión o crea una cuenta para dejar un comentario
u/Ivoah June 22, 2016, 05:05:39 PM
Quote from: Hayleia on June 22, 2016, 04:17:20 PM
No idea if that's the right place to post, especially since I'm mostly asking for 3DS dev but since it might apply to C in general, I posted here...

So, is there a way to detect what functions are never called from a certain starting function, recursively?
Example, if you didn't get what I said.

int a() {
    return 1;
}
int b() {
    return 2;
}
int c() {
    return a()+1;
}
int main() {
  return c()+2;
}

Well, then.
- what functions aren't called from a? b, c, main.
- what functions aren't called from b? a, c, main.
- what functions aren't called from c? b, main (a is called directly from c).
- what functions aren't called from main? b (c is called directly from main and a is called indirectly from c).

So is there something that can parse my files and tell me this?
Note, this has to be a tool that happens before execution since, as I said, this is going to be executed from the 3DS, so I can't really run the compiled executable through some IDE tool that sends stuff to GDB or whatever, that won't work.
Sounds like you want a static analyzer, here's one for C: http://clang-analyzer.llvm.org/
u/Hayleia June 22, 2016, 06:08:30 PM
Thanks :)
In the meantime, I also discovered cflow. Not sure which one suits my needs best, I'll see.

edit Seems like cflow -r *.c | grep -x -E "[^ ].*|[ ]*main.*" gives an output that fulfills my need correctly (if I didn't fail, it should list all the functions in the .c files, either with nothing under them or with mentions of "main" which mean they are called by main).
Last Edit: June 22, 2016, 07:26:59 PM by Hayleia
u/Yuki June 23, 2016, 05:52:38 AM
Depending of the compiler, I think they do a good job at removing unused and unreachable code when you ask for it through compiler options (like -O in GCC). But better audit the code yourself and comment out/remove the unused code, I guess.
u/novenary June 26, 2016, 05:39:05 PM
Quote from: Juju on June 23, 2016, 05:52:38 AM
Depending of the compiler, I think they do a good job at removing unused and unreachable code when you ask for it through compiler options (like -O in GCC). But better audit the code yourself and comment out/remove the unused code, I guess.
Actually unless you enable LTO, you need to add specific linker flags for that to happen. Otherwise it can't  know what to remove since code in other objects may call it.
u/Hayleia June 26, 2016, 06:00:59 PM
This probably works when compiling a regular PC program but adding -flto to my cflags didn't remove anything to my compiled armloaderhax payload for 3DS :P
Removing unused functions by hand did though. Went down from 90KB to 12 :)
Start a Discussion

b/PC, Mac & Vintage Computers

Computer programming discussion and project showcase

132
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal