GCC를 사용하면 &&
라벨의 주소를 알 수 있습니다. ICC는 비슷한 기능을 가지고 있습니까? 나는 그것에 관한 문서를 찾을 수 없었다.ICC의 라벨 주소
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdint.h>
int main(int argc, char **argv)
{
int (*my_printf) (const char *format, ...);
void (*my_exit) (int);
void *page = (void *) ((unsigned long) (&&checkpoint) & ~(getpagesize() - 1));
/* mark the code section we are going to overwrite
* as writable.
*/
mprotect(page, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC);
/* Use the labels to avoid having GCC
* optimize them out */
switch (argc) {
case 33:
goto checkpoint;
case 44:
goto newcode;
case 55:
goto newcode_end;
default:
break;
}
/* Replace code in checkpoint with code from
* newcode.
*/
//memcpy(&&checkpoint, &&newcode, &&newcode_end - &&newcode);
checkpoint:
printf("Good morning!\n");
return 1;
newcode:
my_printf = &printf;
(*(my_printf)) ("Good evening\n");
my_exit = &exit;
(*(my_exit)) (0);
newcode_end:
return 2;
}
그렇지 않은 경우에는 그렇지 않습니다. 표준 기능이 아닙니다. –
@ H2CO3 : 그러나 ICC는 gcc와 밀접하게 호환되도록 시도합니다. –