So I think I get what's happening here. My assumption is that you have myfunc() and testfunc() in a separate file, without any other functions, yes? It seems the KEEP() statement in the ld file is enough to not garbage-collect the function that would normally be garbage-collected by --gc-sections... however, ld seems to do a separate, per-file garbage collection that discards the entire .o file if nothing in it is referenced anywhere else.
The easiest way to let ld think it's referenced (without actually referencing the function in code) is to add a -u line to the ld commandline. In esp-idf, you can do that by adding
Code: Select all
COMPONENT_ADD_LDFLAGS += -u myfunc0
to the component.mk file of the component the myfunc0 is defined in.