5

Is it possible to use a switch statement without a jump table? GCC creates stupid (and in my case unusable) jump tables which I want to avoid.

kaetzacoatl
  • 1,419
  • 1
  • 19
  • 27
  • 2
    can you elaborate your question a bit more? example scenario. – Sourav Ghosh Jul 09 '14 at 18:12
  • 5
    What do you find distasteful about the jump table GCC creates for you? Are you sure fighting the compiler is what you need to do to achieve your goal? – Santa Jul 09 '14 at 18:13
  • @Santa on some platforms (e.g. arm) for jump tables a builtin is used (e.g. `__gnu_thumb1_case_sqi`) which is not included when `-nostdlib` or `-nodefaultlibs` is specified. So the jump table effectively generates code that does not work when not eventually linked against something providing `__gnu_thumb1_case_sqi`. I found that distasteful. – mvds Dec 16 '18 at 11:28

1 Answers1

12

https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

-fno-jump-tables

Do not use jump tables for switch statements even where it would be more efficient than other code generation strategies. This option is of use in conjunction with -fpic or -fPIC for building code that forms part of a dynamic linker and cannot reference the address of a jump table. On some targets, jump tables do not require a GOT and this option is not needed.

Scotty Bauer
  • 1,277
  • 9
  • 14