From ceae4a44f39e3157a872062124c94c35e97ac7ba Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sat, 23 Nov 2019 22:21:11 +0100 Subject: [PATCH 1/3] Stop using `f(un)?lockfile` Those are only useful for locking file IO across threads, but RGBLINK is single-threaded anyways, so they don't matter. Plus, they aren't provided by mingw, so that'll remove part of the problem --- src/link/output.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/link/output.c b/src/link/output.c index 1ddd1aa1..597d2d8f 100644 --- a/src/link/output.c +++ b/src/link/output.c @@ -188,10 +188,6 @@ static void writeROM(void) checkOverlay(); if (outputFile) { - flockfile(outputFile); - if (overlayFile) - flockfile(overlayFile); - if (sections[SECTTYPE_ROM0].nbBanks > 0) writeBank(sections[SECTTYPE_ROM0].banks[0].sections, 0x0000, 0x4000); @@ -199,10 +195,6 @@ static void writeROM(void) for (uint32_t i = 0 ; i < sections[SECTTYPE_ROMX].nbBanks; i++) writeBank(sections[SECTTYPE_ROMX].banks[i].sections, 0x4000, 0x4000); - - if (overlayFile) - funlockfile(overlayFile); - funlockfile(outputFile); } closeFile(outputFile); From 68410d35d37fc72dfc4f55ea2e7d04b9bb2829d1 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sat, 23 Nov 2019 23:00:44 +0100 Subject: [PATCH 2/3] Get rid of `unlocked_stdio` functions Those did not provide a significant speedup, and are not provided by mingw --- src/link/output.c | 11 ++++------- src/link/script.c | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/link/output.c b/src/link/output.c index 597d2d8f..37913e71 100644 --- a/src/link/output.c +++ b/src/link/output.c @@ -150,9 +150,8 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset, /* Output padding up to the next SECTION */ while (offset + baseOffset < section->org) { - putc_unlocked(overlayFile ? getc_unlocked(overlayFile) - : padValue, - outputFile); + putc(overlayFile ? getc(overlayFile) : padValue, + outputFile); offset++; } @@ -162,7 +161,7 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset, if (overlayFile) { /* Skip bytes even with pipes */ for (uint16_t i = 0; i < section->size; i++) - getc_unlocked(overlayFile); + getc(overlayFile); } offset += section->size; @@ -170,9 +169,7 @@ static void writeBank(struct SortedSection *bankSections, uint16_t baseOffset, } while (offset < size) { - putc_unlocked(overlayFile ? getc_unlocked(overlayFile) - : padValue, - outputFile); + putc(overlayFile ? getc(overlayFile) : padValue, outputFile); offset++; } } diff --git a/src/link/script.c b/src/link/script.c index 3a854f06..f691778d 100644 --- a/src/link/script.c +++ b/src/link/script.c @@ -164,7 +164,7 @@ static char const * const commands[] = { static int readChar(FILE *file) { - int curchar = getc_unlocked(file); + int curchar = getc(file); if (curchar == EOF && ferror(file)) err(1, "%s(%u): Unexpected error in %s", linkerScriptName, From d93ad2e650282ddc211aedb28fe0bc10aec2f23b Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sat, 23 Nov 2019 23:07:39 +0100 Subject: [PATCH 3/3] Rename all functions imported from musl This is to avoid conflicting with libraries, which occurred in the mingw builds --- include/extern/getopt.h | 2 +- src/asm/main.c | 4 ++-- src/extern/getopt.c | 20 ++++++++++---------- src/fix/main.c | 4 ++-- src/gfx/main.c | 4 ++-- src/link/main.c | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/extern/getopt.h b/include/extern/getopt.h index 5eab2968..4eead270 100644 --- a/include/extern/getopt.h +++ b/include/extern/getopt.h @@ -36,7 +36,7 @@ struct option { int val; }; -int getopt_long_only(int, char **, const char *, const struct option *, int *); +int musl_getopt_long_only(int, char **, const char *, const struct option *, int *); #define no_argument 0 #define required_argument 1 diff --git a/src/asm/main.c b/src/asm/main.c index 2962536e..03c1db46 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -317,8 +317,8 @@ int main(int argc, char *argv[]) newopt = CurrentOptions; - while ((ch = getopt_long_only(argc, argv, optstring, longopts, - NULL)) != -1) { + while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, + NULL)) != -1) { switch (ch) { case 'b': if (strlen(optarg) == 2) { diff --git a/src/extern/getopt.c b/src/extern/getopt.c index 834ad4e9..118fd11d 100644 --- a/src/extern/getopt.c +++ b/src/extern/getopt.c @@ -33,7 +33,7 @@ int __optpos, __optreset; -void __getopt_msg(const char *a, const char *b, const char *c, size_t l) +void musl__getopt_msg(const char *a, const char *b, const char *c, size_t l) { FILE *f = stderr; (void)(fputs(a, f)>=0 @@ -52,9 +52,9 @@ static void permute(char **argv, int dest, int src) av[dest] = tmp; } -static int __getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly); +static int musl__getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly); -static int __getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly) +static int musl__getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly) { int ret, skipped, resumed; if (!optind || __optreset) { @@ -73,7 +73,7 @@ static int __getopt_long(int argc, char **argv, const char *optstring, const str optind = i; } resumed = optind; - ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly); + ret = musl__getopt_long_core(argc, argv, optstring, longopts, idx, longonly); if (resumed > skipped) { int i, cnt = optind-resumed; for (i=0; i