How can i fix MinGW -Wl, --dynamicbase not working properly? - windows

I just read about ASLR, and i found gcc have related flag for ASLR from here. The flag is -Wl,--dynamicbase, so i try it with this command gcc test.c -Wl,--dynamicbase -o test.exe. I try run it and everything runs well, but when i check for ASLR with ProcessExplorer, it looks like ASLR for my program is turned off. I continue reading and find this flag -pie -fPIE, then i try again with this command gcc test.c -Wl,--dynamicbase -o test.exe -pie -fPIE, but after i run, the program receive SIGSEGV. I don't know for sure what is the problem. So could you give me the right flag or what i miss? My computer support for ASLR, i know it because ProcessExplorer show some process with ASLR turned on. Thanks for your attention.
test.c
#include <stdio.h>
int main(){
puts("lol");
}

Related

Automating GCC Compiler arguments to create easier compilations - Windows OS?

Goal
When I run the command:
gcc -ggdb -std=c99 -Wall -Werror hello.c -lcs50 -o test.exe from the root directory
I am able to build the test.exe file and when I run test.exe all is well (thanks to this post by Manohar Reddy Poreddy)
However all of those flags are a little bit cumbersome and I think it would great to condense them into a 'make' command or similar. How would I do this on windows?
Context
GCC, G++ and GDB all seem to be correctly linked (I used chocolatey which paths everything automatically)
Okay so I found what I was looking for.
I hope this answer can help others. Turns out the utility is called 'make' (no surprises). In your directory you essentially create a 'makefile' where you can include your command line arguments which saves on repeated typing in the command line for each compile.
Here is an excellent response on how to install 'make' for windows and was perfect for my use case as a Chocolatey user.
I also found this resource which helps newcomers begin to get their head round GCC which I highly recommend if you're coming into this like I was and felt completely out of your depth.

How to compile kernel with debug symbols for my own OS?

Hi I'm a beginner and trying to write a Linux like kernel.
I use Qemu as my emulator and currently debug in a assembly level.
However, by previous experience, I can debug Linux kernel with Qemu at source code (.c files) level.
So I would like to ask if I can do it with my own kernel, so that I can debug it with efficiency.
In order to provide more info, the following is my compilation script:
# Complie head.S
gcc -E ./PysicCodes/head.S > head.s
as --64 -o head.o head.s
gcc -E ./PysicCodes/AP_Boot.S > AP_Boot.s
as --64 -o AP_Boot.o AP_Boot.s
# Compile main program
gcc -mcmodel=large -fno-builtin -fno-stack-protector -m64 -c ./PysicCodes/*.c
# Interrupt hander requires general register only(since no XMM,SEE registers are saved)
gcc -mcmodel=large -fno-builtin -fno-stack-protector -m64 -mgeneral-regs-only -c ./PysicCodes/g_reg_only/*.c
# Linkage: Must put head.o at first, so that kernel start at head.o
ld -b elf64-x86-64 -z muldefs -o system head.o 8529A.o ACPI.o AP_Boot.o APIC.o cpu.o INT.o keyboard.o main.o Mem.o PCI.o Printk.o SMP.o Task.o Time.o TSS.o fat32.o -T ./PysicCodes/Kernel.lds
# Dump kernel
objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary system Kernel.bin
Thanks for anyone who would spend time on helping. Any extra information needed, please comment.
Currently I tried to add -ggdb3 as the compiling and linking options.
Furthermore, using the compiled object as the option for gdb
It simply worked.
In addition, adding "miDebuggerServerAddress": "localhost:1234" into Vscode's "launch.json" file, it actually can connect to Qemu and debug c code in vscode.
However only 1 problem, that vscode will run Qemu at start, so I have to press pause button as soon as I can after start debugger, and using "-exec" to put a hardware break-point.
There is an issue on git and currently haven't see an answer.

gcc / (g)as ignore breakpoint trap (x86)

I've written a C program which includes some assembler code in which I have some instructions which lead to a breakpoint exception (INT3) This is nice when debugging (since you don't have to save and restore the breakpoints when restarting the gdb session).
But now I want to disable these traps, which is possible by the -no-break or the -no-trap option of as (the gnu assembler), but I don't find a way to specify these options as options of gcc so that gcc passes the option down to as.
Is there a way to do so? (somehow gcc -g -o file -Xassembler -no-trap main.c file.S does not work)

How to prevent clang from turning "#warning ..." statement into error when -Werror is used?

Gcc has a compiler option -Wno-error=cpp which prevents compiler from turning "#warning ..." into error. However, clang doesn't support this option. Does clang have similar option?
Clang option -Wno-error=\#warnings is equivalent of gcc's -Wno-error=cpp. Escape \ is needed in Linux. Verified with clang-3.8 in Linux.

gccfilter and gcc 4.7.2 does not work, stops compiling

I have successfully installed the gccfilter (http://www.mixtion.org/gccfilter/) in my toolchain. The filter should actually work because all perl modules and other stuff has been installed the problem is that it does not work properly when I use for example the following command line:
gccfilter -c -a g++ -std=c++11 -O3 -DNDEBUG -I/"tonnes of includes" -o CMakeFiles/...../main.cpp.o
-c /...path.../App/main.cpp
.../variant.hpp:17:0,
from .../SceneParser.hpp:12,
from .../SimulationManager.hpp:12,
from .../main.cpp:8:
_ <-- Cursor is here
It compiles but after the error message it stops doing anything, the cursor is on the bottom line and nothing happens?
So the tool does not quite work, I am using gcc 4.7.2. i am not quite sure where the problem might be?

Resources