Skip to content

Commit b3db6a5

Browse files
committed
Fix recomp modding macros for C++ compatibility
1 parent 85fd5b8 commit b3db6a5

4 files changed

Lines changed: 36 additions & 19 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"compilerPath": "clang",
1818
"cStandard": "c99",
19+
"cppStandard": "c++20",
1920
"intelliSenseMode": "clang-x86"
2021
}
2122
],

Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ endif
1616
TARGET := $(BUILD_DIR)/mod.elf
1717

1818
LDSCRIPT := mod.ld
19-
CFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \
20-
-fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset \
21-
-Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable \
22-
-Wno-missing-braces -Wno-unsupported-floating-point-opt -Werror=section
23-
CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -DF3DEX_GBI_2 -DF3DEX_GBI_PL -DGBI_DOWHILE -I include -I include/dummy_headers \
24-
-I mm-decomp/include -I mm-decomp/src -I mm-decomp/extracted/n64-us -I mm-decomp/include/libc
25-
LDFLAGS := -nostdlib -T $(LDSCRIPT) -Map $(BUILD_DIR)/mod.map --unresolved-symbols=ignore-all --emit-relocs -e 0 --no-nmagic
19+
ARCHFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \
20+
-fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset
21+
WARNFLAGS := -Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable \
22+
-Wno-missing-braces -Wno-unsupported-floating-point-opt -Werror=section
23+
CFLAGS := $(ARCHFLAGS) $(WARNFLAGS) -D_LANGUAGE_C -nostdinc -ffunction-sections
24+
CPPFLAGS := -DMIPS -DF3DEX_GBI_2 -DF3DEX_GBI_PL -DGBI_DOWHILE -I include -I include/dummy_headers \
25+
-I mm-decomp/include -I mm-decomp/src -I mm-decomp/extracted/n64-us -idirafter include/libc -idirafter mm-decomp/include/libc
26+
LDFLAGS := -nostdlib -T $(LDSCRIPT) -Map $(BUILD_DIR)/mod.map --unresolved-symbols=ignore-all --emit-relocs -e 0 --no-nmagic -gc-sections
2627

2728
C_SRCS := $(wildcard src/*.c)
2829
C_OBJS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.o))
2930
C_DEPS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.d))
3031

32+
ALL_OBJS := $(C_OBJS)
33+
ALL_DEPS := $(C_DEPS)
34+
3135
all: $(TARGET)
3236

33-
$(TARGET): $(C_OBJS) $(LDSCRIPT) | $(BUILD_DIR)
34-
$(LD) $(C_OBJS) $(LDFLAGS) -o $@
37+
$(TARGET): $(ALL_OBJS) $(LDSCRIPT) | $(BUILD_DIR)
38+
$(LD) $(ALL_OBJS) $(LDFLAGS) -o $@
3539

3640
$(BUILD_DIR) $(BUILD_DIR)/src:
3741
ifeq ($(OS),Windows_NT)
@@ -50,6 +54,6 @@ else
5054
rm -rf $(BUILD_DIR)
5155
endif
5256

53-
-include $(C_DEPS)
57+
-include $(ALL_DEPS)
5458

5559
.PHONY: clean all

include/modding.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@
33

44
// Do not edit these defines. They use special section names that the recomp mod tool recognizes for specific modding functionality.
55

6+
#ifdef __cplusplus
7+
# define EXTERNC extern "C"
8+
#else
9+
# define EXTERNC
10+
#endif
11+
12+
// The RECOMP_IMPORT has the following attributes:
13+
// noinline: Prevent import function definitions from being inlined, allowing the mod tool to find relocs.
14+
// weak: Allow import definitions to be in headers without triggering multiple definition errors.
615
#define RECOMP_IMPORT(mod, func) \
716
_Pragma("GCC diagnostic push") \
817
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
918
_Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
10-
__attribute__((noinline, weak, used, section(".recomp_import." mod))) func {} \
19+
EXTERNC __attribute__((noinline, weak, used, section(".recomp_import." mod))) func {} \
1120
_Pragma("GCC diagnostic pop")
1221

13-
#define RECOMP_EXPORT __attribute__((section(".recomp_export")))
22+
#define RECOMP_EXPORT EXTERNC __attribute__((retain, section(".recomp_export")))
1423

15-
#define RECOMP_PATCH __attribute__((section(".recomp_patch")))
24+
#define RECOMP_PATCH EXTERNC __attribute__((retain, section(".recomp_patch")))
1625

17-
#define RECOMP_FORCE_PATCH __attribute__((section(".recomp_force_patch")))
26+
#define RECOMP_FORCE_PATCH EXTERNC __attribute__((retain, section(".recomp_force_patch")))
1827

1928
#define RECOMP_DECLARE_EVENT(func) \
2029
_Pragma("GCC diagnostic push") \
2130
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
22-
__attribute__((noinline, weak, used, section(".recomp_event"))) void func {} \
31+
EXTERNC __attribute__((retain, noinline, weak, used, section(".recomp_event"))) void func {} \
2332
_Pragma("GCC diagnostic pop")
2433

25-
#define RECOMP_CALLBACK(mod, event) __attribute__((section(".recomp_callback." mod ":" #event)))
34+
#define RECOMP_CALLBACK(mod, event) __attribute__((retain, section(".recomp_callback." mod ":" #event)))
2635

27-
#define RECOMP_HOOK(func) __attribute__((section(".recomp_hook." func)))
36+
#define RECOMP_HOOK(func) __attribute__((retain, section(".recomp_hook." func)))
2837

29-
#define RECOMP_HOOK_RETURN(func) __attribute__((section(".recomp_hook_return." func)))
38+
#define RECOMP_HOOK_RETURN(func) __attribute__((retain, section(".recomp_hook_return." func)))
3039

3140
#endif

include/z64recomp_api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#ifndef __Z64RECOMP_API_H__
22
#define __Z64RECOMP_API_H__
33

4-
#include "z64actor.h"
54
#include "modding.h"
5+
#include "PR/ultratypes.h"
6+
7+
// Pull in the Actor typedef to avoid needing to include the entirety of z64actor.h.
8+
typedef struct Actor Actor;
69

710
typedef u32 ActorExtensionId;
811

0 commit comments

Comments
 (0)