https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84011
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Richard Biener from comment #1) > Somehow switch-conversion doesn't transform the switch with -f{PIE,PIC}. > Without > we get > > phy_modes (phy_interface_t interface) > { > const char * _1; > const char * _4; > > <bb 2> [local count: 1073741825]: > if (interface_2(D) <= 22) > goto <bb 3>; [50.00%] > else > goto <bb 4>; [50.00%] > > <bb 3> [local count: 536870912]: > _4 = CSWTCH.0[interface_2(D)]; > > <bb 4> [local count: 1073741825]: > # _1 = PHI <_4(3), "unknown"(2)> > return _1; > > due to > > Bailing out - value from a case would need runtime relocations > > reloc = initializer_constant_valid_p (val, TREE_TYPE > (val)); > if ((flag_pic && reloc != null_pointer_node) > || (!flag_pic && reloc == NULL_TREE)) > { > if (reloc) > reason > = "value from a case would need runtime > relocations"; > else > reason > = "value from a case is not a valid initializer"; > } > > not sure why we need relocations for string constants? They do need run-time relocations: /export/build/gnu/gcc-test/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-test/build-x86_64-linux/gcc/ -O2 -fpic -S -o f.s f.i [hjl@gnu-skl-1 pr82303]$ cat f.s .file "f.i" .text .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "unknown" .text .p2align 4,,15 .globl phy_modes .type phy_modes, @function phy_modes: .LFB0: .cfi_startproc leaq .LC0(%rip), %rax cmpl $22, %edi ja .L1 movl %edi, %edi leaq CSWTCH.0(%rip), %rax movq (%rax,%rdi,8), %rax .L1: ret .cfi_endproc .LFE0: .size phy_modes, .-phy_modes .section .rodata.str1.1 .LC1: .string "" .LC2: .string "internal" .LC3: .string "mii" .LC4: .string "gmii" .LC5: .string "sgmii" .LC6: .string "tbi" .LC7: .string "rev-mii" .LC8: .string "rmii" .LC9: .string "rgmii" .LC10: .string "rgmii-id" .LC11: .string "rgmii-rxid" .LC12: .string "rgmii-txid" .LC13: .string "rtbi" .LC14: .string "smii" .LC15: .string "xgmii" .LC16: .string "moca" .LC17: .string "qsgmii" .LC18: .string "trgmii" .LC19: .string "1000base-x" .LC20: .string "2500base-x" .LC21: .string "rxaui" .LC22: .string "xaui" .LC23: .string "10gbase-kr" .section .data.rel.ro.local,"aw",@progbits .align 32 .type CSWTCH.0, @object .size CSWTCH.0, 184 CSWTCH.0: .quad .LC1 .quad .LC2 .quad .LC3 .quad .LC4 .quad .LC5 .quad .LC6 .quad .LC7 .quad .LC8 .quad .LC9 .quad .LC10 .quad .LC11 .quad .LC12 .quad .LC13 .quad .LC14 .quad .LC15 .quad .LC16 .quad .LC17 .quad .LC18 .quad .LC19 .quad .LC20 .quad .LC21 .quad .LC22 .quad .LC23 .ident "GCC: (GNU) 8.0.1 20180117 (experimental)" .section .note.GNU-stack,"",@progbits [hjl@gnu-skl-1 pr82303]$ gcc -c f.s [hjl@gnu-skl-1 pr82303]$ readelf -rW f.o Relocation section '.rela.text' at offset 0x370 contains 2 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000000003 0000000a00000002 R_X86_64_PC32 0000000000000000 .LC0 - 4 0000000000000011 0000000700000002 R_X86_64_PC32 0000000000000000 .data.rel.ro.local - 4 Relocation section '.rela.data.rel.ro.local' at offset 0x3a0 contains 23 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000000000 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 8 0000000000000008 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 9 0000000000000010 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 12 0000000000000018 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 16 0000000000000020 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 1b 0000000000000028 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 21 0000000000000030 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 25 0000000000000038 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 2d 0000000000000040 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 32 0000000000000048 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 38 0000000000000050 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 41 0000000000000058 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 4c 0000000000000060 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 57 0000000000000068 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 5c 0000000000000070 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 61 0000000000000078 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 67 0000000000000080 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 6c 0000000000000088 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 73 0000000000000090 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 7a 0000000000000098 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 85 00000000000000a0 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 90 00000000000000a8 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 96 00000000000000b0 0000000500000001 R_X86_64_64 0000000000000000 .rodata.str1.1 + 9b Relocation section '.rela.eh_frame' at offset 0x5c8 contains 1 entry: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000000020 0000000200000002 R_X86_64_PC32 0000000000000000 .text + 0 [hjl@gnu-skl-1 pr82303]$ The question is why run-time relocations aren't allowed.