I think I figured it out now. I used gcc to compile PIC for the C switch statement and checked what it does. I don't fully understand it to be honest, but it seems to do the job also for non PIC code. For posterity, here is the code: .text .global jump_table .type jump_table, @function jump_table: # Push stack pointer so we can make room for local storage. push %rax mov $0x02, %rax # Move index into rax; 2 is supposed to end up at label_02. lea 0(,%rax, 4), %rdx lea table(%rip), %rax mov (%rdx, %rax), %edx movslq %edx, %rdx lea table(%rip), %rax lea (%rdx, %rax), %rax jmp *%rax .section .rodata .align 4 table: .long label_00-table .long label_01-table .long label_02-table .long label_03-table .text label_00: jmp done label_01: jmp done label_02: jmp done label_03: jmp done done: pop %rax ret .size jump_table, .-jump_table On 03/15/11 18:25, Brian Raiter wrote: >> I am trying to write a jump table, but unfortunately with limited >> success. When I compile the code and disassemble it, the offset of >> "table" is 0, which I guess means that something didn't work out. > > Actually, table appears immediately following your indirect jump > instruction, so I would assume that the offset would be zero. Did you > actually try this code to verify that it doesn't do what you expect? > > b > -- > To unsubscribe from this list: send the line "unsubscribe linux-assembly" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at http://vger.kernel.org/majordomo-info.html
Attachment:
signature.asc
Description: OpenPGP digital signature
- Follow-Ups:
- Re: writing a jump table
- From: Brian Raiter
- Re: writing a jump table
- References:
- writing a jump table
- From: Nicolas Bock
- Re: writing a jump table
- From: Brian Raiter
- writing a jump table
- Prev by Date: Re: writing a jump table
- Next by Date: Re: writing a jump table
- Previous by thread: Re: writing a jump table
- Next by thread: Re: writing a jump table
- Index(es):