Skip to content

Commit

Permalink
IDO 7.1 C++ compiler (#53)
Browse files Browse the repository at this point in the history
* C++ files

* Initial support for edgcpfe

* start making the libc_impl functions

* /usr/lib/DCC redirection and non implemented functions

* cp CC 7.1

* CC for mac

* edgcpfe  hack

* fix mac

* Rename CC to NCC

* wrapper_getopt

* wrapper_fputc

* somewhat progress on getopt

* proc_command_line testing

* maybe finally works?

* remove some prints

* delete some files

* cleanup

* remove getopt debug strings

* more cleanup

* format

* Update DOCS.md

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

---------

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
  • Loading branch information
AngheloAlf and hensldm authored Sep 10, 2023
1 parent e1320ea commit c4d24ce
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 64 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ ctx.c.m2c
*.s

.DS_Store


*.T
*.o
*.ii
*.B
*.G
12 changes: 9 additions & 3 deletions DOCS.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Custom Functionality

## Redirection

IDO recomp currently has two forms of path redirection, both involving the `/usr` folder.

### `/usr/lib`
In order for users to not having to worry about installing the binaries in particular locations in `/usr/lib`, recomp automatically redirects `/usr/lib/` paths. This is done by determining the location of `cc` and redirecting to the same directory. This does mean all the binaries and `err.english.cc` are expected to be a part of a single flattened directory.
### `/usr/lib` and `/usr/lib/DCC`

In order for users to not having to worry about installing the binaries in particular locations in `/usr/lib` or `/usr/lib/DCC`, recomp automatically redirects `/usr/lib/` and `/usr/lib/DCC` paths. This is done by determining the location of `cc` and redirecting to the same directory. This does mean all the binaries and `err.english.cc` are expected to be a part of a single flattened directory.

It is also possible to override the auto redirect by using the environment variable `USR_LIB` with the desired redirection path. This can be used if the binaries are not in a flattened directory with `cc` or if on Linux and are unable to read `/proc/self/exe`.

Wrapper functions implementing this redirection:

* `init_file`
* `wrapper_execvp`
* `wrapper_open`

### `/usr/include`

### /usr/include
The other form of redirection is completely optional and is done by setting the environment variable `USR_INCLUDE` to the desired redirection path. This will than redirect all opened files files there. This is done so that the `mdebug` section file paths will still use `/usr/include` path, but the files themselves can be located elsewhere for greater flexibility.

Wrapper functions implementing this redirection:

* `wrapper_open`
70 changes: 57 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ASAN ?= 0
ifeq ($(VERSION),7.1)
IDO_VERSION := IDO71
# copt currently does not build
IDO_TC := cc acpp as0 as1 cfe ugen ujoin uld umerge uopt usplit upas
IDO_TC := cc acpp as0 as1 cfe ugen ujoin uld umerge uopt usplit upas edgcpfe NCC
IDO_LIBS :=
else ifeq ($(VERSION),5.3)
IDO_VERSION := IDO53
Expand Down Expand Up @@ -109,7 +109,7 @@ ERR_STRS := $(BUILT_BIN)/err.english.cc
LIBS := $(foreach lib,$(IDO_LIBS),$(BUILT_BIN)/$(lib))

RECOMP_ELF := $(BUILD_BASE)/recomp.elf
LIBC_IMPL_O := libc_impl.o
LIBC_IMPL := libc_impl

TARGET_BINARIES := $(foreach binary,$(IDO_TC),$(BUILT_BIN)/$(binary))
O_FILES := $(foreach binary,$(IDO_TC),$(BUILD_DIR)/$(binary).o)
Expand Down Expand Up @@ -138,8 +138,8 @@ ifeq ($(DETECTED_OS),linux)
$(RECOMP_ELF): LDFLAGS += -Wl,-export-dynamic
endif

%/$(LIBC_IMPL_O): CFLAGS += -D$(IDO_VERSION)
%/$(LIBC_IMPL_O): WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations
%/$(LIBC_IMPL).o: WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations
%/$(LIBC_IMPL)_53.o: WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations

#### Main Targets ###

Expand Down Expand Up @@ -212,42 +212,86 @@ $(shell mkdir -p $(FAT_FOLDERS))
FAT_BINARIES := $(foreach binary,$(IDO_TC),$(BUILT_BIN)/arm64-apple-macos11/$(binary)) \
$(foreach binary,$(IDO_TC),$(BUILT_BIN)/x86_64-apple-macos10.14/$(binary))

### Fat ###

$(BUILT_BIN)/%: $(BUILD_DIR)/arm64-apple-macos11/% $(BUILD_DIR)/x86_64-apple-macos10.14/% | $(ERR_STRS)
lipo -create -output $@ $^


$(BUILD_DIR)/arm64-apple-macos11/%: $(BUILD_DIR)/arm64-apple-macos11/%.o $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL_O) | $(ERR_STRS)
### Built programs ###

$(BUILD_DIR)/arm64-apple-macos11/%: $(BUILD_DIR)/arm64-apple-macos11/%.o $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL).o | $(ERR_STRS)
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target arm64-apple-macos11 -o $@ $^ $(LDFLAGS)
$(STRIP) $@

$(BUILD_DIR)/x86_64-apple-macos10.14/%: $(BUILD_DIR)/x86_64-apple-macos10.14/%.o $(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL_O) | $(ERR_STRS)
$(BUILD_DIR)/x86_64-apple-macos10.14/%: $(BUILD_DIR)/x86_64-apple-macos10.14/%.o $(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL).o | $(ERR_STRS)
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target x86_64-apple-macos10.14 -o $@ $^ $(LDFLAGS)
$(STRIP) $@

$(BUILD_BASE)/7.1/arm64-apple-macos11/NCC: $(BUILD_BASE)/7.1/arm64-apple-macos11/cc
cp $^ $@

$(BUILD_BASE)/7.1/x86_64-apple-macos10.14/NCC: $(BUILD_BASE)/7.1/x86_64-apple-macos10.14/cc
cp $^ $@

$(BUILD_DIR)/arm64-apple-macos11/edgcpfe: $(BUILD_DIR)/arm64-apple-macos11/edgcpfe.o $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL)_53.o | $(ERR_STRS)
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target arm64-apple-macos11 -o $@ $^ $(LDFLAGS)
$(STRIP) $@

$(BUILD_DIR)/x86_64-apple-macos10.14/edgcpfe: $(BUILD_DIR)/x86_64-apple-macos10.14/edgcpfe.o $(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL)_53.o | $(ERR_STRS)
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target x86_64-apple-macos10.14 -o $@ $^ $(LDFLAGS)
$(STRIP) $@


### Intermediary steps ###

$(BUILD_DIR)/arm64-apple-macos11/%.o: $(BUILD_DIR)/%.c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -target arm64-apple-macos11 -o $@ $<

$(BUILD_DIR)/x86_64-apple-macos10.14/%.o: $(BUILD_DIR)/%.c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -target x86_64-apple-macos10.14 -o $@ $<


$(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL_O): libc_impl.c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) $(WARNINGS) -target arm64-apple-macos11 -o $@ $<
$(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL).o: $(LIBC_IMPL).c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -D$(IDO_VERSION) $(WARNINGS) -target arm64-apple-macos11 -o $@ $<

$(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL).o: $(LIBC_IMPL).c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -D$(IDO_VERSION) $(WARNINGS) -target x86_64-apple-macos10.14 -o $@ $<

$(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -DIDO53 $(WARNINGS) -target arm64-apple-macos11 -o $@ $<

$(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL_O): libc_impl.c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) $(WARNINGS) -target x86_64-apple-macos10.14 -o $@ $<
$(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -DIDO53 $(WARNINGS) -target x86_64-apple-macos10.14 -o $@ $<

else
$(BUILT_BIN)/%: $(BUILD_DIR)/%.o $(BUILD_DIR)/$(LIBC_IMPL_O) | $(ERR_STRS)
### Built programs ###

$(BUILT_BIN)/%: $(BUILD_DIR)/%.o $(BUILD_DIR)/$(LIBC_IMPL).o | $(ERR_STRS)
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(STRIP) $@

# NCC 7.1 is just a renamed cc
$(BUILD_BASE)/7.1/out/NCC: $(BUILD_BASE)/7.1/out/cc
cp $^ $@

# edgcpfe 7.1 uses libc 5.3, so we need to hack a way to link a libc_impl file with the 5.3 stuff
$(BUILT_BIN)/edgcpfe: $(BUILD_DIR)/edgcpfe.o $(BUILD_DIR)/$(LIBC_IMPL)_53.o | $(ERR_STRS)
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(STRIP) $@


### Intermediary steps ###

$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -o $@ $<


$(BUILD_DIR)/$(LIBC_IMPL_O): libc_impl.c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) $(WARNINGS) -o $@ $<
$(BUILD_DIR)/$(LIBC_IMPL).o: $(LIBC_IMPL).c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -D$(IDO_VERSION) $(WARNINGS) -o $@ $<

$(BUILD_DIR)/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -DIDO53 $(WARNINGS) -o $@ $<
endif

# Remove built-in rules, to improve performance
Expand Down
Binary file added ido/7.1/usr/lib/DCC/delta_init.o
Binary file not shown.
Binary file added ido/7.1/usr/lib/DCC/driver
Binary file not shown.
Binary file added ido/7.1/usr/lib/DCC/edgcpfe
Binary file not shown.
Binary file added ido/7.1/usr/lib/libC.so.1
Binary file not shown.
Binary file added ido/7.1/usr/lib/libmalloc_cv.so
Binary file not shown.
Binary file added ido/7.1/usr/lib/pixie.a
Binary file not shown.
Binary file added ido/7.1/usr/lib/pixie_32.a
Binary file not shown.
Binary file added ido/7.1/usr/lib/pixie_64.a
Binary file not shown.
Loading

0 comments on commit c4d24ce

Please sign in to comment.