Can I find a list of all the build instructions that GCC can generate?

In homework for the first day of Xeno Kovah Introduction to the x86 assembly hosted on OpenSecurityTraining , he assigns,

Instructions We Now Know (24)

NOP PUSH / POP CALL / RET MOV / LEA ADD / SUB JMP / Jcc CMP / TEST AND / OR / XOR / NOT SHR / SHL IMUL / DIV REP STOS, REP MOV VACATION

Write a program to find instructions that we did not review, and to report training tomorrow.

Then he predicts the appointment,

  • Instructions to be considered later that are not taken into account: SAL/SAR
  • Variations on jumps or options MUL/ IDIV IMUL/ are DIValso not taken into account
  • Additional disabling instructions: any floating point (since we do not close the ones in this class.)
  • He says in the video that you cannot use the built-in assembly. (mentioned when asked).

Instead of objdumpexecuting arbitrary executable file and checking them, and then creating the source, is it possible to find the list of x86 build instructions that GCC currently issues?

The reason for this question is that there is a very small subset of the actually used commands that you need to know in order to reverse engineer (which is the focus of the course). Xeno seems to be trying to find a fun instructive way to make this point,

I think that knowing about 20-30 (not counting the variations) is good enough for you to check the manual very rarely

, OpenSecurityTraining, GCC ( ). , Xeno.;)

+4
2

, ,

, . , gcc , enter ( , push rbp/mov rbp, rsp/sub rsp, some_constant ).

/ , xlat loop, , , gcc -Os , . (clang -Oz , IDK, - loop.)

, , gcc , wrmsr. intrinsics (__builtin_...) rdtsc cpuid, "".


x86, GCC ?

gcc. GCC , . ( , , - "" .)

gcc-internals.


x86 (, HTML- . tag wiki) , . , gcc .

. movsx ( ),

long long foo(int x) { return x; }

gcc -O3 ( Godbolt)

    movsx   rax, edi
    ret

cdqe (aka cltq AT & T) rax, gcc eax ( lea).

long long bar(unsigned x) { return (int)(x+1); }

    lea     eax, [rdi+1]
    cdqe
    ret

   # clang chooses inc edi  /  movsxd rax, edi

. Matt Godbolt CppCon2017 talk: ? strong > "" GCC/clang?.


, gcc . () ++. shifts/OR, gcc .

C , (, popcnt, / ), - . gcc clang popcnt -mpopcnt (, , -march=haswell), . , . __builtin_popcount(), popcnt, , . _mm_popcnt_u64 is popcnt : , .


, , , x86 !

( , gcc , inline rep cmpsb , , . rep movs/rep stos " " . , gcc lods "" rep.)

+3

, , , x86, GCC ?

, gcc. gcc/config/i386 .md. x86 i386.md; x86 (, , ).

: .

, 20-30 ( ) ,

; , , 99% , ; , x86, , , .


, , , , ( ):

SSE co...

+2

Source: https://habr.com/ru/post/1694202/


All Articles