mirror of
https://github.com/rui314/mold.git
synced 2024-11-13 09:39:13 +03:00
[Mach-O] wip
This commit is contained in:
parent
74244c3c9c
commit
4932daadba
@ -59,6 +59,10 @@ public:
|
||||
|
||||
class Subsection {
|
||||
public:
|
||||
std::string_view get_contents() {
|
||||
return sec.contents.substr(input_offset, input_size);
|
||||
}
|
||||
|
||||
const InputSection &sec;
|
||||
u32 input_offset = 0;
|
||||
u32 input_size = 0;
|
||||
@ -140,6 +144,7 @@ class OutputSection : public Chunk {
|
||||
public:
|
||||
OutputSection(std::string_view name);
|
||||
void compute_size(Context &ctx) override;
|
||||
void copy_buf(Context &ctx) override;
|
||||
|
||||
std::vector<Subsection *> members;
|
||||
};
|
||||
|
@ -236,12 +236,22 @@ OutputSection::OutputSection(std::string_view name) {
|
||||
}
|
||||
|
||||
void OutputSection::compute_size(Context &ctx) {
|
||||
SyncOut(ctx) << "members: " << members.size();
|
||||
hdr.size = 0;
|
||||
for (Subsection *subsec : members)
|
||||
hdr.size += subsec->input_size;
|
||||
}
|
||||
|
||||
void OutputSection::copy_buf(Context &ctx) {
|
||||
u8 *buf = ctx.buf + hdr.offset;
|
||||
i64 offset = 0;
|
||||
|
||||
for (Subsection *subsec : members) {
|
||||
std::string_view data = subsec->get_contents();
|
||||
memcpy(buf + offset, data.data(), data.size());
|
||||
offset += data.size();
|
||||
}
|
||||
}
|
||||
|
||||
OutputSegment::OutputSegment(std::string_view name, u32 prot, u32 flags) {
|
||||
assert(name.size() <= sizeof(cmd.segname));
|
||||
|
||||
|
@ -3,7 +3,7 @@ set -e
|
||||
cd $(dirname $0)
|
||||
mold=`pwd`/../../ld64.mold
|
||||
echo -n "Testing $(basename -s .sh $0) ... "
|
||||
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
|
||||
t=$(pwd)/../../out/test/macho/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
$mold -o $t/exe
|
||||
|
@ -3,14 +3,18 @@ set -e
|
||||
cd $(dirname $0)
|
||||
mold=`pwd`/../../ld64.mold
|
||||
echo -n "Testing $(basename -s .sh $0) ... "
|
||||
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
|
||||
t=$(pwd)/../../out/test/macho/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -xc -
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
void hello() {
|
||||
printf("Hello world\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
hello();
|
||||
}
|
||||
EOF
|
||||
|
||||
$mold -o $t/hello $t/a.o
|
||||
|
Loading…
Reference in New Issue
Block a user