{"action":"created","issue":{"url":"https://api.github.com/repos/avr-llvm/llvm/issues/162","labels_url":"https://api.github.com/repos/avr-llvm/llvm/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/avr-llvm/llvm/issues/162/comments","events_url":"https://api.github.com/repos/avr-llvm/llvm/issues/162/events","html_url":"https://github.com/avr-llvm/llvm/issues/162","id":104786558,"number":162,"title":"Function pointer miscalculation.","user":{"login":"majkrzak","id":3064914,"avatar_url":"https://avatars.githubusercontent.com/u/3064914?v=3","gravatar_id":"","url":"https://api.github.com/users/majkrzak","html_url":"https://github.com/majkrzak","followers_url":"https://api.github.com/users/majkrzak/followers","following_url":"https://api.github.com/users/majkrzak/following{/other_user}","gists_url":"https://api.github.com/users/majkrzak/gists{/gist_id}","starred_url":"https://api.github.com/users/majkrzak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/majkrzak/subscriptions","organizations_url":"https://api.github.com/users/majkrzak/orgs","repos_url":"https://api.github.com/users/majkrzak/repos","events_url":"https://api.github.com/users/majkrzak/events{/privacy}","received_events_url":"https://api.github.com/users/majkrzak/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/avr-llvm/llvm/labels/blocks-arduino","name":"blocks-arduino","color":"006b75"},{"url":"https://api.github.com/repos/avr-llvm/llvm/labels/broken-output","name":"broken-output","color":"5319e7"},{"url":"https://api.github.com/repos/avr-llvm/llvm/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/avr-llvm/llvm/labels/kind-mc","name":"kind-mc","color":"006b75"},{"url":"https://api.github.com/repos/avr-llvm/llvm/labels/priority-high","name":"priority-high","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"dylanmckay","id":7722159,"avatar_url":"https://avatars.githubusercontent.com/u/7722159?v=3","gravatar_id":"","url":"https://api.github.com/users/dylanmckay","html_url":"https://github.com/dylanmckay","followers_url":"https://api.github.com/users/dylanmckay/followers","following_url":"https://api.github.com/users/dylanmckay/following{/other_user}","gists_url":"https://api.github.com/users/dylanmckay/gists{/gist_id}","starred_url":"https://api.github.com/users/dylanmckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylanmckay/subscriptions","organizations_url":"https://api.github.com/users/dylanmckay/orgs","repos_url":"https://api.github.com/users/dylanmckay/repos","events_url":"https://api.github.com/users/dylanmckay/events{/privacy}","received_events_url":"https://api.github.com/users/dylanmckay/received_events","type":"User","site_admin":false},"milestone":null,"comments":4,"created_at":"2015-09-03T21:36:19Z","updated_at":"2015-12-30T10:10:08Z","closed_at":null,"body":"It seems that avr-llvm have problem with calculating proper addresses of functions during casting to function pointer. Following code demonstrates it:\r\n\r\n```c\r\nvoid foo(){}\r\nint jmp __attribute__((section(\".vectors\"))) = 0x940C;\r\nvoid (*ptr)()  __attribute__((section(\".vectors\"))) = (&foo);\r\n\r\n// avr-gcc -mmcu=atmega328p -nostdlib ptrs.c &&  avr-objdump -SDh   \r\n/*  \r\n * a.out:     file format elf32-avr\r\n * \r\n * Sections:\r\n * Idx Name          Size      VMA       LMA       File off  Algn\r\n *   0 .text         00000014  00000000  00000000  00000074  2**1\r\n *                   CONTENTS, ALLOC, LOAD, READONLY, CODE\r\n *   1 .data         00000000  00800060  00000014  00000088  2**0\r\n *                   CONTENTS, ALLOC, LOAD, DATA\r\n *   2 .comment      00000011  00000000  00000000  00000088  2**0\r\n *                   CONTENTS, READONLY\r\n * \r\n * Disassembly of section .text:\r\n * \r\n * 00000000 <jmp>:\r\n *    0:   0c 94 02 00     jmp     0x4     ; 0x4 <foo>\r\n * \r\n * 00000002 <ptr>:\r\n *    2:   02 00           .word   0x0002  ; ????\r\n * \r\n * 00000004 <foo>:\r\n *    4:   cf 93           push    r28\r\n *    6:   df 93           push    r29\r\n *    8:   cd b7           in      r28, 0x3d       ; 61\r\n *    a:   de b7           in      r29, 0x3e       ; 62\r\n *    c:   00 00           nop\r\n *    e:   df 91           pop     r29\r\n *   10:   cf 91           pop     r28\r\n *   12:   08 95           ret\r\n * \r\n * Disassembly of section .comment:\r\n * \r\n * 00000000 <.comment>:\r\n *    0:   47 43           sbci    r20, 0x37       ; 55\r\n *    2:   43 3a           cpi     r20, 0xA3       ; 163\r\n *    4:   20 28           or      r2, r0\r\n *    6:   47 4e           sbci    r20, 0xE7       ; 231\r\n *    8:   55 29           or      r21, r5\r\n *    a:   20 35           cpi     r18, 0x50       ; 80\r\n *    c:   2e 32           cpi     r18, 0x2E       ; 46\r\n *    e:   2e 30           cpi     r18, 0x0E       ; 14\r\n *         ...\r\n */\r\n\r\n// clang --target=avr -mmcu=atmega328p -nostdlib ptrs.c &&  avr-objdump -SDh\r\n/*  \r\n * a.out:     file format elf32-avr\r\n * \r\n * Sections:\r\n * Idx Name          Size      VMA       LMA       File off  Algn\r\n *  0 .text         00000006  00000000  00000000  00000054  2**2\r\n *                  CONTENTS, ALLOC, LOAD, READONLY, CODE\r\n *  1 .data         00000000  00800060  00800060  0000005a  2**0\r\n *                  CONTENTS, ALLOC, LOAD, DATA\r\n * \r\n * Disassembly of section .text:\r\n * \r\n * 00000000 <jmp>:\r\n *   0:   0c 94 04 00     jmp     0x8     ; 0x8 <_etext+0x2>\r\n * \r\n * 00000002 <ptr>:\r\n *   2:   04 00           .word   0x0004  ; ????\r\n * \r\n * 00000004 <foo>:\r\n *   4:   08 95           ret\r\n * \r\n */\r\n```"},"comment":{"url":"https://api.github.com/repos/avr-llvm/llvm/issues/comments/167972210","html_url":"https://github.com/avr-llvm/llvm/issues/162#issuecomment-167972210","issue_url":"https://api.github.com/repos/avr-llvm/llvm/issues/162","id":167972210,"user":{"login":"majkrzak","id":3064914,"avatar_url":"https://avatars.githubusercontent.com/u/3064914?v=3","gravatar_id":"","url":"https://api.github.com/users/majkrzak","html_url":"https://github.com/majkrzak","followers_url":"https://api.github.com/users/majkrzak/followers","following_url":"https://api.github.com/users/majkrzak/following{/other_user}","gists_url":"https://api.github.com/users/majkrzak/gists{/gist_id}","starred_url":"https://api.github.com/users/majkrzak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/majkrzak/subscriptions","organizations_url":"https://api.github.com/users/majkrzak/orgs","repos_url":"https://api.github.com/users/majkrzak/repos","events_url":"https://api.github.com/users/majkrzak/events{/privacy}","received_events_url":"https://api.github.com/users/majkrzak/received_events","type":"User","site_admin":false},"created_at":"2015-12-30T10:10:08Z","updated_at":"2015-12-30T10:10:08Z","body":"> ### Atmega 328p datasheet: \r\n> #### 8.2 In-System Reprogrammable Flash Program Memory\r\n> Since all AVR instructions are 16 or 32 bits wide, the Flash is organized as 2/4/8/16K x 16.\r\n\r\nFunction pointers should address each 16 bits of FLASH not like regular pointers that points to 8 bit SRAM cells.\r\n"}}