* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Know what C functions aren't called from a certain function?  (Read 786 times)

0 Members and 1 Guest are viewing this topic.

Offline Hayleia

  • Full User
  • Join Date: Nov 2014
  • Location:
  • Posts: 324
  • Post Rating Ratio: +12/-0
    • View Profile
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.
Code: [Select]
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.



Offline Ivoah

  • Super User
  • Join Date: Dec 2014
  • Location:
  • Posts: 523
  • Post Rating Ratio: +6/-0
    • @NoahRosamilia
    • Ivoah
    • @UCmgDyh_AeaHALohvR7PKXIw
    • /u/Ivoah
    • Ivoah
    • 114/11421
    • View Profile
    • Codinghobbit
  • Gender: Male
  • WalriiPoints: 100
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.
Code: [Select]
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/
  • Calculators owned: TI-86 (now broken), TI SR-56, TI-Nspire CX CAS, TI-84+ SE, TI-84+ SE, TI-85, TI-73 Explorer VS, ViewScreen, TI-84+ CSE, TI-83+ SE

Offline Hayleia

  • Full User
  • Join Date: Nov 2014
  • Location:
  • Posts: 324
  • Post Rating Ratio: +12/-0
    • View Profile
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 »

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 2834
  • Post Rating Ratio: +18/-1
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • View Profile
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
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.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????:trollface:???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

Offline Streetwalrus

  • Professional slacker
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Original 5
  • Join Date: Nov 2014
  • Location: Israel
  • Posts: 2856
  • Post Rating Ratio: +20/-0
  • ƎW∀⅁ ƎH⊥
    • View Profile
  • Gender: Male
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.
  • Calculators owned: TI-80, HP 40G, TI-84 Plus rev G (yay 128k RAM), TI-83 Plus Silver Edition (broken LCD), TI-82 Stats.fr (black), TI-Nspire CX rev C (yay Nlaunchy), TI-83+ SE ViewScreen



Offline Hayleia

  • Full User
  • Join Date: Nov 2014
  • Location:
  • Posts: 324
  • Post Rating Ratio: +12/-0
    • View Profile
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 :)

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games