Skip to content

Commit 4710043

Browse files
authored
---
yaml --- r: 344063 b: refs/heads/master-rebranch c: 4fcef2b h: refs/heads/master i: 344061: 75aefee 344059: 86b162b 344055: 1a7f4a3 344047: 50e2673 344031: 047cc43 343999: 5584e73 343935: c9ce9bd 343807: aefcb24 343551: 29c818f 343039: ac9f22a 342015: 9ff9009 339967: 9abfd9b 335871: f3948ef 327679: a75c9d3
1 parent 527140e commit 4710043

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 78ae7ac9dbf3beb10933a18026c194906233f3f1
1458+
refs/heads/master-rebranch: 4fcef2b9f458d24f4aabe425900a86e51832fbdd
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/docs/SIL.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ the Swift programming language. SIL accommodates the following use cases:
1717
such as definitive initialization of variables and constructors, code
1818
reachability, switch coverage.
1919
- High-level optimization passes, including retain/release optimization,
20-
dynamic method devirtualization, closure inlining, memory allocation promotion,
21-
and generic function instantiation.
20+
dynamic method devirtualization, closure inlining, promoting heap allocations
21+
to stack allocations, promoting stack allocations to SSA registers, scalar
22+
replacement of aggregates (splitting aggregate allocations into multiple
23+
smaller allocations), and generic function instantiation.
2224
- A stable distribution format that can be used to distribute "fragile"
2325
inlineable or generic code with Swift library modules, to be optimized into
2426
client binaries.

branches/master-rebranch/include/swift/Reflection/ReflectionContext.h

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class ReflectionContext
123123
return sizeof(StoredPointer) * 2;
124124
}
125125

126-
#if defined(__APPLE__) && defined(__MACH__)
127126
template <typename T> bool readMachOSections(RemoteAddress ImageStart) {
128127
auto Buf =
129128
this->getReader().readBytes(ImageStart, sizeof(typename T::Header));
@@ -277,22 +276,6 @@ class ReflectionContext
277276
return true;
278277
}
279278

280-
bool addImage(RemoteAddress ImageStart) {
281-
// We start reading 4 bytes. The first 4 bytes are supposed to be
282-
// the magic, so we understand whether this is a 32-bit executable or
283-
// a 64-bit one.
284-
auto Buf = this->getReader().readBytes(ImageStart, sizeof(uint32_t));
285-
if (!Buf)
286-
return false;
287-
auto HeaderMagic = reinterpret_cast<const uint32_t *>(Buf.get());
288-
if (*HeaderMagic == llvm::MachO::MH_MAGIC)
289-
return readMachOSections<MachOTraits<4>>(ImageStart);
290-
if (*HeaderMagic == llvm::MachO::MH_MAGIC_64)
291-
return readMachOSections<MachOTraits<8>>(ImageStart);
292-
return false;
293-
}
294-
295-
#elif defined(_WIN32)
296279
bool readPECOFFSections(RemoteAddress ImageStart) {
297280
auto DOSHdrBuf = this->getReader().readBytes(
298281
ImageStart, sizeof(llvm::object::dos_header));
@@ -384,15 +367,13 @@ class ReflectionContext
384367
return true;
385368
}
386369

387-
bool addImage(RemoteAddress ImageStart) {
370+
bool readPECOFF(RemoteAddress ImageStart) {
388371
auto Buf = this->getReader().readBytes(ImageStart,
389372
sizeof(llvm::object::dos_header));
390373
if (!Buf)
391374
return false;
392375

393376
auto DOSHdr = reinterpret_cast<const llvm::object::dos_header *>(Buf.get());
394-
if (!(DOSHdr->Magic[0] == 'M' && DOSHdr->Magic[1] == 'Z'))
395-
return false;
396377

397378
auto PEHeaderAddress =
398379
ImageStart.getAddressData() + DOSHdr->AddressOfNewExeHeader;
@@ -407,7 +388,7 @@ class ReflectionContext
407388

408389
return readPECOFFSections(ImageStart);
409390
}
410-
#else // ELF platforms.
391+
411392
template <typename T> bool readELFSections(RemoteAddress ImageStart) {
412393
auto Buf =
413394
this->getReader().readBytes(ImageStart, sizeof(typename T::Header));
@@ -506,8 +487,8 @@ class ReflectionContext
506487
savedBuffers.push_back(std::move(Buf));
507488
return true;
508489
}
509-
510-
bool addImage(RemoteAddress ImageStart) {
490+
491+
bool readELF(RemoteAddress ImageStart) {
511492
auto Buf =
512493
this->getReader().readBytes(ImageStart, sizeof(llvm::ELF::Elf64_Ehdr));
513494

@@ -527,12 +508,48 @@ class ReflectionContext
527508
return false;
528509
}
529510
}
530-
#endif
511+
512+
bool addImage(RemoteAddress ImageStart) {
513+
// Read the first few bytes to look for a magic header.
514+
auto Magic = this->getReader().readBytes(ImageStart, sizeof(uint32_t));
515+
if (!Magic)
516+
return false;
517+
518+
uint32_t MagicWord;
519+
memcpy(&MagicWord, Magic.get(), sizeof(MagicWord));
520+
521+
// 32- and 64-bit Mach-O.
522+
if (MagicWord == llvm::MachO::MH_MAGIC) {
523+
return readMachOSections<MachOTraits<4>>(ImageStart);
524+
}
525+
526+
if (MagicWord == llvm::MachO::MH_MAGIC_64) {
527+
return readMachOSections<MachOTraits<8>>(ImageStart);
528+
}
529+
530+
// PE. (This just checks for the DOS header; `readPECOFF` will further
531+
// validate the existence of the PE header.)
532+
auto MagicBytes = (const char*)Magic.get();
533+
if (MagicBytes[0] == 'M' && MagicBytes[1] == 'Z') {
534+
return readPECOFF(ImageStart);
535+
}
536+
537+
// ELF.
538+
if (MagicBytes[0] == llvm::ELF::ElfMagic[0]
539+
&& MagicBytes[1] == llvm::ELF::ElfMagic[1]
540+
&& MagicBytes[2] == llvm::ELF::ElfMagic[2]
541+
&& MagicBytes[3] == llvm::ELF::ElfMagic[3]) {
542+
return readELF(ImageStart);
543+
}
544+
545+
// We don't recognize the format.
546+
return false;
547+
}
531548

532549
void addReflectionInfo(ReflectionInfo I) {
533550
getBuilder().addReflectionInfo(I);
534551
}
535-
552+
536553
bool ownsObject(RemoteAddress ObjectAddress) {
537554
auto MetadataAddress = readMetadataFromInstance(ObjectAddress.getAddressData());
538555
if (!MetadataAddress)

0 commit comments

Comments
 (0)