fortrangoingonforty/afs-ld / e00ea8a

Browse files

Add output section model

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e00ea8a9ed5fb4bb97f047e0a7877eb3c461fc94
Parents
1f6d509
Tree
f65cf04

2 changed files

StatusFile+-
M src/macho/mod.rs 1 0
M src/section.rs 67 0
src/macho/mod.rsmodified
@@ -10,3 +10,4 @@ pub mod exports;
1010
 pub mod reader;
1111
 pub mod tbd;
1212
 pub mod tbd_yaml;
13
+pub mod writer;
src/section.rsmodified
@@ -10,6 +10,7 @@
1010
 
1111
 use crate::macho::constants::*;
1212
 use crate::macho::reader::{name16_str, ReadError, Section64Header};
13
+use crate::resolve::AtomId;
1314
 
1415
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
1516
 pub enum SectionKind {
@@ -213,6 +214,72 @@ impl InputSection {
213214
     }
214215
 }
215216
 
217
+// ---------------------------------------------------------------------------
218
+// Output layout model — populated by Sprint 10's layout pass.
219
+// ---------------------------------------------------------------------------
220
+
221
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
222
+pub struct OutputSectionId(pub u32);
223
+
224
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
225
+pub struct Prot(u32);
226
+
227
+impl Prot {
228
+    pub const NONE: Prot = Prot(0);
229
+    pub const READ: Prot = Prot(1);
230
+    pub const WRITE: Prot = Prot(2);
231
+    pub const EXECUTE: Prot = Prot(4);
232
+    pub const READ_ONLY: Prot = Prot(Self::READ.0);
233
+    pub const READ_WRITE: Prot = Prot(Self::READ.0 | Self::WRITE.0);
234
+    pub const READ_EXECUTE: Prot = Prot(Self::READ.0 | Self::EXECUTE.0);
235
+
236
+    pub fn bits(self) -> u32 {
237
+        self.0
238
+    }
239
+}
240
+
241
+#[derive(Debug, Clone, PartialEq, Eq)]
242
+pub struct OutputAtom {
243
+    pub atom: AtomId,
244
+    pub offset: u64,
245
+    pub size: u64,
246
+    pub data: Vec<u8>,
247
+}
248
+
249
+#[derive(Debug, Clone, PartialEq, Eq)]
250
+pub struct OutputSection {
251
+    pub segment: String,
252
+    pub name: String,
253
+    pub kind: SectionKind,
254
+    pub align_pow2: u8,
255
+    pub flags: u32,
256
+    pub reserved1: u32,
257
+    pub reserved2: u32,
258
+    pub reserved3: u32,
259
+    pub atoms: Vec<OutputAtom>,
260
+    pub addr: u64,
261
+    pub size: u64,
262
+    pub file_off: u64,
263
+}
264
+
265
+#[derive(Debug, Clone, PartialEq, Eq)]
266
+pub struct OutputSegment {
267
+    pub name: String,
268
+    pub sections: Vec<OutputSectionId>,
269
+    pub vm_addr: u64,
270
+    pub vm_size: u64,
271
+    pub file_off: u64,
272
+    pub file_size: u64,
273
+    pub init_prot: Prot,
274
+    pub max_prot: Prot,
275
+}
276
+
277
+impl OutputSection {
278
+    pub fn is_zerofill(&self) -> bool {
279
+        is_zerofill(self.kind)
280
+    }
281
+}
282
+
216283
 #[cfg(test)]
217284
 mod tests {
218285
     use super::*;