Skip to content

Commit 6922b22

Browse files
committed
More android patches
1 parent 79882ce commit 6922b22

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

compiler/ghc/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ let
326326
" '*.ghc.cabal.configure.opts += --flags=-dynamic-system-linker'"
327327
# The following is required if we build on aarch64-darwin for aarch64-iOS. Otherwise older
328328
# iPhones/iPads/... won't understand the compiled code, as the compiler will emit LDSETALH
329-
# + lib.optionalString (targetPlatform.???) "'*.rts.ghc.c.opts += -optc-mcpu=apple-a7 -optc-march=armv8-a+norcpc'"
329+
# FIXME: we should have iOS as an argument to this derivation, and then make this, as well as
330+
# disableLargeAddress space conditional on iOS = true.
331+
+ lib.optionalString (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) "'*.rts.ghc.c.opts += -optc-mcpu=apple-a7 -optc-march=armv8-a+norcpc'"
330332
# For GHC versions in the 9.x range that don't support the +native_bignum flavour transformer yet
331333
+ lib.optionalString ((enableNativeBignum && !hadrianHasNativeBignumFlavour))
332334
" --bignum=native"

overlays/patches/ghc/ghc-9.6-iog.patch

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ index 59e2ff9397..78e43cd471 100644
2626
o_so->next = openedSOs;
2727
openedSOs = o_so;
2828
@@ -1314,7 +1314,7 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
29-
30-
29+
30+
3131
IF_DEBUG(linker, debugBelch("mkOc: %" PATH_FMT "\n", path));
3232
- oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)");
3333
+ oc = stgCallocBytes(1, sizeof(ObjectCode), "mkOc(oc)");
34-
34+
3535
oc->info = NULL;
3636
oc->type = type;
3737
@@ -1334,7 +1334,7 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
3838
oc->fileName = pathdup(path);
39-
39+
4040
if (archiveMemberName) {
4141
- oc->archiveMemberName = stgMallocBytes( (pathlen(archiveMemberName)+1) * pathsize,
4242
+ oc->archiveMemberName = stgCallocBytes(1, (pathlen(archiveMemberName)+1) * pathsize,
@@ -50,17 +50,17 @@ index 59e2ff9397..78e43cd471 100644
5050
- image = stgMallocBytes(fileSize + misalignment, "loadObj(image)");
5151
+ image = stgCallocBytes(1, fileSize + misalignment, "loadObj(image)");
5252
image += misalignment;
53-
53+
5454
# else /* !defined(darwin_HOST_OS) */
55-
55+
5656
- image = stgMallocBytes(fileSize, "loadObj(image)");
5757
+ image = stgCallocBytes(1, fileSize, "loadObj(image)");
58-
58+
5959
#endif /* !defined(darwin_HOST_OS) */
60-
60+
6161
@@ -1787,6 +1787,8 @@ static HsInt resolveObjs_ (void)
6262
IF_DEBUG(linker, debugBelch("resolveObjs: start\n"));
63-
63+
6464
for (ObjectCode *oc = objects; oc; oc = oc->next) {
6565
+ if(oc->status == OBJECT_RESOLVED)
6666
+ continue;
@@ -73,7 +73,7 @@ index 59e2ff9397..78e43cd471 100644
7373
ProddableBlock* pb
7474
- = stgMallocBytes(sizeof(ProddableBlock), "addProddableBlock");
7575
+ = stgCallocBytes(1,sizeof(ProddableBlock), "addProddableBlock");
76-
76+
7777
IF_DEBUG(linker, debugBelch("addProddableBlock: %p %p %d\n", oc, start, size));
7878
ASSERT(size > 0);
7979
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
@@ -83,7 +83,7 @@ index 271611a249..784bb19c10 100644
8383
@@ -299,6 +299,10 @@ struct _ObjectCode {
8484
int n_segments;
8585
Segment *segments;
86-
86+
8787
+ // COMMON section
8888
+ void * common_mem;
8989
+ unsigned long common_size;
@@ -106,9 +106,9 @@ index 4cac10ba15..fe0d8ca40e 100644
106106
+ memset(space, 0, count*size);
107107
return space;
108108
}
109-
109+
110110
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
111-
index bab2ca3041..5d91301c51 100644
111+
index bab2ca3041..9f623a62da 100644
112112
--- a/rts/linker/Elf.c
113113
+++ b/rts/linker/Elf.c
114114
@@ -303,6 +303,15 @@ ocInit_ELF(ObjectCode * oc)
@@ -125,7 +125,7 @@ index bab2ca3041..5d91301c51 100644
125125
+ oc->common_mem = NULL;
126126
+ oc->common_size = 0;
127127
}
128-
128+
129129
void
130130
@@ -961,14 +970,17 @@ ocGetNames_ELF ( ObjectCode* oc )
131131
for (size_t j = 0; j < symTab->n_symbols; j++) {
@@ -149,17 +149,19 @@ index bab2ca3041..5d91301c51 100644
149149
barf("ocGetNames_ELF: Failed to allocate memory for SHN_COMMONs");
150150
}
151151
}
152-
@@ -1010,8 +1022,9 @@ ocGetNames_ELF ( ObjectCode* oc )
152+
@@ -1009,9 +1021,10 @@ ocGetNames_ELF ( ObjectCode* oc )
153+
if (shndx == SHN_COMMON) {
153154
isLocal = false;
154155
CHECK(common_used < common_size);
155-
CHECK(common_mem);
156+
- CHECK(common_mem);
156157
- symbol->addr = (void*)((uintptr_t)common_mem + common_used);
157158
- common_used += symbol->elf_sym->st_size;
159+
+ CHECK(oc->common_mem);
158160
+ int alignment = symbol->elf_sym->st_value-1;
159161
+ symbol->addr = (void*)(((uintptr_t)oc->common_mem + common_used + alignment) & ~alignment);
160162
+ common_used = (uintptr_t)symbol->addr - (uintptr_t)oc->common_mem + symbol->elf_sym->st_size;
161163
CHECK(common_used <= common_size);
162-
164+
163165
IF_DEBUG(linker_verbose,
164166
@@ -1025,7 +1038,9 @@ ocGetNames_ELF ( ObjectCode* oc )
165167
|| ELF_ST_BIND(symbol->elf_sym->st_info) == STB_WEAK
@@ -187,10 +189,25 @@ index bab2ca3041..5d91301c51 100644
187189
if (ELF_ST_BIND(symbol->elf_sym->st_info) == STB_LOCAL) {
188190
isLocal = true;
189191
isWeak = false;
190-
@@ -1070,35 +1093,20 @@ ocGetNames_ELF ( ObjectCode* oc )
191-
sym_type = SYM_TYPE_CODE;
192+
@@ -1063,42 +1086,20 @@ ocGetNames_ELF ( ObjectCode* oc )
193+
isWeak = ELF_ST_BIND(symbol->elf_sym->st_info)
194+
== STB_WEAK;
195+
}
196+
- }
197+
-
198+
- SymType sym_type;
199+
- if (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC) {
200+
- sym_type = SYM_TYPE_CODE;
201+
+ } else if (ELF_ST_BIND(symbol->elf_sym->st_info) == STB_WEAK
202+
+ && shndx == SHN_UNDEF
203+
+ && (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC
204+
+ || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_OBJECT
205+
+ || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_NOTYPE)) {
206+
+ symbol->addr = NULL;
207+
+ isLocal = false;
208+
+ isWeak = true;
192209
} else {
193-
sym_type = SYM_TYPE_DATA;
210+
- sym_type = SYM_TYPE_DATA;
194211
- }
195212
-
196213
- /* And the decision is ... */
@@ -215,16 +232,7 @@ index bab2ca3041..5d91301c51 100644
215232
- }
216233
- } else {
217234
- /* Skip. */
218-
+ } else if (ELF_ST_BIND(symbol->elf_sym->st_info) == STB_WEAK
219-
+ && shndx == SHN_UNDEF
220-
+ && (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC
221-
+ || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_OBJECT
222-
+ || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_NOTYPE)) {
223-
+ symbol->addr = NULL;
224-
+ isLocal = false;
225-
+ isWeak = true;
226-
+ } else {
227-
+ /* skip this symbol */
235+
+ /* Skip. */
228236
IF_DEBUG(linker_verbose,
229237
debugBelch("skipping `%s'\n",
230238
nm)
@@ -233,28 +241,37 @@ index bab2ca3041..5d91301c51 100644
233241
/*
234242
debugBelch(
235243
"skipping bind = %d, type = %d, secno = %d `%s'\n",
236-
@@ -1108,7 +1116,24 @@ ocGetNames_ELF ( ObjectCode* oc )
244+
@@ -1108,7 +1109,34 @@ ocGetNames_ELF ( ObjectCode* oc )
237245
nm
238246
);
239247
*/
240-
- }
241248
+ continue;
242-
+ }
249+
}
250+
+
251+
+ SymType sym_type;
252+
+ if (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC) {
253+
+ sym_type = SYM_TYPE_CODE;
254+
+ } else {
255+
+ sym_type = SYM_TYPE_DATA;
256+
+ }
243257
+
244258
+ /* And the decision is ... */
245-
+ ASSERT(nm != NULL);
259+
+ CHECK(nm != NULL);
246260
+ /* Acquire! */
247261
+ if (!isLocal) {
248262
+
249263
+ if (isWeak == HS_BOOL_TRUE) {
250264
+ setWeakSymbol(oc, nm);
251265
+ }
252266
+ if (!ghciInsertSymbolTable(oc->fileName, symhash,
253-
+ nm, symbol->addr, isWeak, oc)) {
267+
+ nm, symbol->addr, isWeak, sym_type, oc)
268+
+ ) {
254269
+ goto fail;
255270
+ }
256-
+ oc->symbols[curSymbol++].name = nm;
271+
+ oc->symbols[curSymbol].name = nm;
257272
+ oc->symbols[curSymbol].addr = symbol->addr;
273+
+ oc->symbols[curSymbol].type = sym_type;
274+
+ curSymbol++;
258275
+ }
259276
}
260277
}
@@ -267,12 +284,12 @@ index 9cd42efff2..70817d8b0b 100644
267284
#include "Rts.h"
268285
+#include "RtsUtils.h"
269286
#include "elf_plt.h"
270-
287+
271288
#include <stdbool.h>
272289
@@ -51,7 +52,7 @@ makeStub(Section * section,
273290
void* * addr,
274291
uint8_t flags) {
275-
292+
276293
- Stub * s = calloc(1, sizeof(Stub));
277294
+ Stub * s = stgCallocBytes(1, sizeof(Stub), "makeStub");
278295
ASSERT(s != NULL);

0 commit comments

Comments
 (0)