Conditional declaration of code and data sections

Having told the compiler what output format we are expecting, we need to declare the sections. Since we are writing portable code, we will use two macros to properly declare code and data sections for each of the formats mentioned earlier. As we are used to seeing a data section after the code section (at least in this book, as the order may vary), we will declare a macro responsible for the proper declaration of the beginning of the code section first:

macro begin_code_section
{
if ACTIVE_TARGET = TARGET_W32_DLL
section '.text' code readable executable
; This is not obligatory, but nice to have - the DllMain procedure
DllMain:
xor eax, eax
inc eax
ret 4 * 3

else if ACTIVE_TARGET = TARGET_W32_OBJ
section '.text' code readable executable

else if ACTIVE_TARGET = TARGET_W64_DLL
section '.text' code readable executable
; DllMain procedure for 64-bit Windows DLL
DllMain:
xor rax, rax
inc eax
ret

else if ACTIVE_TARGET = TARGET_W64_OBJ
section '.text' code readable executable

else if ACTIVE_TARGET = TARGET_L32_O
section '.text' executable

else if ACTIVE_TARGET = TARGET_L64_O
section '.text' executable

end if
}

We will follow it by the macro declaring data section:

macro begin_data_section
{
if ACTIVE_TARGET = TARGET_W32_DLL
section '.data' data readable writeable

else if ACTIVE_TARGET = TARGET_W32_OBJ
section '.data' data readable writeable

else if ACTIVE_TARGET = TARGET_W64_DLL
section '.data' data readable writeable

else if ACTIVE_TARGET = TARGET_W64_OBJ
section '.data' data readable writeable align 16

else if ACTIVE_TARGET = TARGET_L32_O
section '.data' writeable

else if ACTIVE_TARGET = TARGET_L64_O
section '.data' writeable

end if
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset