aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2022-09-07 14:15:14 +0200
committerToni Uhlig <matzeton@googlemail.com>2022-09-07 14:15:14 +0200
commit3be8cccbdbb548a4538d23470aa20e65b33e7815 (patch)
tree8ca086f53f417dbae2b222cabaeef3238c5c8761
parentf50275681b24dbd63de543ff9fabbb396cc15240 (diff)
Added CFLAGS -fno-stack-protector -mno-stack-arg-probe. Maybe __chkstk_ms() will be implemented in the future.
* Support for custom global/per-target CFLAGS/LDFLAGS Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--Makefile.inc16
-rw-r--r--README.md31
2 files changed, 32 insertions, 15 deletions
diff --git a/Makefile.inc b/Makefile.inc
index 95b7606..8e65b2e 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -32,6 +32,7 @@ DDK_INCLUDE_DIR = $(dir $(CC))../x86_64-w64-mingw32/include/ddk
CFLAGS := -Wall -Wextra -Wno-sign-compare -Wno-strict-aliasing \
-m64 -fPIC -fvisibility=hidden \
-ffunction-sections -fdata-sections -fno-builtin -ffreestanding \
+ -fno-stack-protector -mno-stack-arg-probe \
-I$(DPP_ROOT)/CRT -I$(DDK_INCLUDE_DIR) \
-D__INTRINSIC_DEFINED_InterlockedBitTestAndSet \
-D__INTRINSIC_DEFINED_InterlockedBitTestAndReset
@@ -104,7 +105,7 @@ define BUILD_C_OBJECT
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Source file missing)
$(call is_set,$(2),Second argument: Output object file missing)
- $(Q)$(CC) -std=c99 $(CFLAGS) -c $(1) -o $(2)
+ $(Q)$(CC) -std=c99 $(CFLAGS) $(CUSTOM_CFLAGS) $(CFLAGS_$(2)) -c $(1) -o $(2)
@echo 'CC $(2)'
endef
@@ -112,7 +113,7 @@ define BUILD_CPP_OBJECT
$(call CHECK_REQUIRED_PATHS)
$(call is_set,$(1),First argument: Source file missing)
$(call is_set,$(2),Second argument: Output object file missing)
- $(Q)$(CXX) $(CFLAGS) $(CXXFLAGS) $(EASTL_CXXFLAGS) -c $(1) -o $(2)
+ $(Q)$(CXX) $(CFLAGS) $(CUSTOM_CFLAGS) $(CFLAGS_$(2)) $(CXXFLAGS) $(EASTL_CXXFLAGS) $(CUSTOM_CXXFLAGS) -c $(1) -o $(2)
@echo 'CXX $@'
endef
@@ -127,7 +128,8 @@ define LINK_C_KERNEL_TARGET
-o '$(2)' \
$(1) \
$(DRIVER_CRT) \
- $(DRIVER_LIBS)
+ $(DRIVER_LIBS) \
+ $(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
@@ -140,6 +142,8 @@ define LINK_C_USER_TARGET
-o '$(2)' \
$(1) \
$(EASTL_STATIC_LIB) \
+ $(USER_LIBS) \
+ $(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
@@ -158,7 +162,8 @@ define LINK_CPP_KERNEL_TARGET
$(DRIVER_ADDITIONAL_OBJS) \
$(DRIVER_CRTPLUSPLUS) \
$(EASTL_STATIC_LIB) \
- $(DRIVER_LIBS)
+ $(DRIVER_LIBS) \
+ $(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
@@ -175,7 +180,8 @@ define LINK_CPP_USER_TARGET
$(1) \
$(USER_CRT) \
$(EASTL_STATIC_LIB) \
- $(USER_LIBS)
+ $(USER_LIBS) \
+ $(LDFLAGS_$(2))
@echo 'LD $(2)'
endef
diff --git a/README.md b/README.md
index 4c5e4f0..76d90e4 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-[![Build](https://github.com/utoni/mingw-w64-ddk-template/actions/workflows/build.yml/badge.svg "Github Actions")](https://github.com/utoni/mingw-w64-ddk-template/actions/workflows/build.yml)
-[![Gitlab-CI](https://gitlab.com/utoni/mingw-w64-ddk-template/badges/main/pipeline.svg "Gitlab-CI: main branch")](https://gitlab.com/utoni/mingw-w64-ddk-template/-/pipelines)
-[![Circle-CI](https://circleci.com/gh/utoni/mingw-w64-ddk-template.svg?style=shield "Circle-CI")](https://app.circleci.com/pipelines/github/utoni/mingw-w64-ddk-template)
+[![Build](https://github.com/utoni/mingw-w64-dpp/actions/workflows/build.yml/badge.svg "Github Actions")](https://github.com/utoni/mingw-w64-dpp/actions/workflows/build.yml)
+[![Gitlab-CI](https://gitlab.com/utoni/mingw-w64-dpp/badges/main/pipeline.svg "Gitlab-CI: main branch")](https://gitlab.com/utoni/mingw-w64-dpp/-/pipelines)
+[![Circle-CI](https://circleci.com/gh/utoni/mingw-w64-dpp.svg?style=shield "Circle-CI")](https://app.circleci.com/pipelines/github/utoni/mingw-w64-dpp)
# Mingw64 Driver Plus Plus
@@ -71,7 +71,7 @@ You can also add the toolchain to your path and use it for other projects w/o an
```
make -C [path-to-this-repo] -f Makefile.deps all
-source [path-to-this-repo]/w64-mingw32-sysroot/x86_64/activate.sh
+source [path-to-this-repo]/mingw-w64-sysroot/x86_64/activate.sh
```
## The CRT and CRT++
@@ -96,7 +96,7 @@ Make sure that the symbol `DriverUnload` exists and has the usual ddk function s
`void DriverUnload(_In_ struct _DRIVER_OBJECT * DriverObject)`.
This is required to make ctors/dtors work without calling additional functions in `DriverEntry` / `DriverUnload`.
-Do not forget to disable `C++ name mangeling` if your driver source is compiled with `g++`:
+Do not forget to disable `C++ name mangeling` if your driver source which contains the `DriverEntry` and `DriverUnload` symbols is compiled with `g++`:
```C++
extern "C" {
@@ -125,7 +125,7 @@ If you ran `make -C [path-to-this-repo] deps` before, everything is already done
You can use the Host Build in your Makefile based project with:
-```
+```make
ifndef DPP_ROOT
$(error DPP_ROOT is undefined)
endif
@@ -136,13 +136,24 @@ else
include $(DPP_ROOT)/Makefile.native.inc
endif
+# Driver
DRIVER_NAME = Driver
DRIVER_OBJECTS = $(DRIVER_NAME).opp
DRIVER_TARGET = $(DRIVER_NAME).sys
-
-USERSPACE_NAME = usa$(NAME_SUFFIX)
-USERSPACE_OBJECTS = $(USERSPACE_NAME).opp
-USERSPACE_TARGET = $(USERSPACE_NAME).exe
+DRIVER_LIBS =
+CFLAGS_$(DRIVER_NAME).opp =
+LDFLAGS_$(DRIVER_NAME).sys =
+
+# Userspace
+USER_NAME = usa$(NAME_SUFFIX)
+USER_OBJECTS = $(USERSPACE_NAME).opp
+USER_TARGET = $(USERSPACE_NAME).exe
+USER_LIBS =
+CFLAGS_$(USERSPACE_NAME).opp =
+LDFLAGS_$(USERSPACE_NAME).exe =
+
+# specify additional CFLAGS for kernel/user targets
+CUSTOM_CFLAGS = -I.
%.opp: %.cpp
$(call BUILD_CPP_OBJECT,$<,$@)