1
+ __precompile__ ()
1
2
module ObjFileBase
2
3
3
4
export ObjectHandle, SectionRef, SymbolRef, debugsections
4
5
5
6
export printfield, printentry, printfield_with_color, deref,
6
7
sectionaddress, sectionoffset, sectionsize, sectionname,
7
- load_strtab, readmeta, StrTab, symname
8
+ load_strtab, readmeta, StrTab, symname, Sections, symbolvalue
8
9
9
- import Base: read, seek, readbytes, position, show
10
+ import Base: read, seek, readbytes, position, show, showcompact
10
11
11
12
# ######### ObjFileBase.jl - Basic shared functionality for all object files ####
12
13
#
@@ -80,6 +81,18 @@ readmeta{T<:ObjectHandle}(io::IO, ::Type{T}) =
80
81
@mustimplement seek (oh:: ObjectHandle , args... )
81
82
@mustimplement position (oh:: ObjectHandle )
82
83
84
+ """
85
+ Determine whether an object file is a relocatable (.o) object file.
86
+ """
87
+ function isrelocatable
88
+ end
89
+
90
+ """
91
+ Turn a section name into the object-file specific naming convention.
92
+ """
93
+ function mangle_sname
94
+ end
95
+
83
96
# #
84
97
# These are parameterized on the type of Object Handle. An imaginary Foo
85
98
# fileformat might declare:
@@ -91,21 +104,12 @@ readmeta{T<:ObjectHandle}(io::IO, ::Type{T}) =
91
104
# end
92
105
# #
93
106
107
+ abstract Sections
94
108
abstract SectionRef{T<: ObjectHandle }
95
109
abstract Section{T<: ObjectHandle }
96
110
abstract Relocation{T<: ObjectHandle }
97
111
abstract RelocationRef{T<: ObjectHandle }
98
112
99
- # The size of the actual data contained in the section. This should exclude any
100
- # padding mandated by the file format e.g. due to alignment rules
101
- @mustimplement sectionsize (section:: Section )
102
-
103
- # The offset of the section in the file
104
- @mustimplement sectionoffset (section:: Section )
105
-
106
- # The address of the section in virtual memory
107
- @mustimplement sectionaddress (section:: Section )
108
-
109
113
# The name of the section
110
114
@mustimplement sectionname (section:: SectionRef )
111
115
@@ -121,9 +125,25 @@ abstract SymtabEntry{T<:ObjectHandle}
121
125
122
126
function symname
123
127
end
128
+ function symbolvalue
129
+ end
124
130
131
+ symbolnum (x:: SymbolRef ) = symbolnum (deref (x))
132
+
133
+ """
134
+ The size of the actual data contained in the section. This should exclude any
135
+ padding mandated by the file format e.g. due to alignment rules
136
+ """
125
137
sectionsize (x:: SectionRef ) = sectionsize (deref (x))
138
+
139
+ """
140
+ The address of the section in virtual memory.
141
+ """
126
142
sectionaddress (x:: SectionRef ) = sectionaddress (deref (x))
143
+
144
+ """
145
+ The offset of the section in the file.
146
+ """
127
147
sectionoffset (x:: SectionRef ) = sectionoffset (deref (x))
128
148
129
149
handleT {T} (:: Union {Type{SectionRef{T}}, Type{Section{T}}, Type{SymbolRef{T}},
141
161
142
162
typealias SectionOrRef{T} Union{Section{T},SectionRef{T}}
143
163
144
- sectionsize (sect:: SectionRef ) = sectionsize (deref (sect))
145
- sectionoffset (sect:: SectionRef ) = sectionoffset (deref (sect))
146
-
147
164
seek {T<:ObjectHandle,S} (oh:: T , section:: Section{S} ) =
148
165
(@assert T <: S ; seek (oh,sectionoffset (section)))
149
166
@@ -157,6 +174,7 @@ function readbytes{T<:ObjectHandle,S}(oh::T,sec::Section{S})
157
174
readbytes (oh, sectionsize (sec))
158
175
end
159
176
readbytes (sec:: SectionRef ) = readbytes (handle (sec),deref (sec))
177
+ seek (x:: SectionRef , off) = seek (handle (x), sectionoffset (x)+ off)
160
178
161
179
typealias Maybe{T} Union{T,Void}
162
180
@@ -181,7 +199,10 @@ function DebugSections{T}(oh::T; debug_abbrev = nothing, debug_aranges = nothing
181
199
debug_frame = nothing , debug_info = nothing , debug_line = nothing ,
182
200
debug_macinfo = nothing , debug_pubnames = nothing , debug_loc= nothing ,
183
201
debug_ranges = nothing , debug_str = nothing , debug_types = nothing )
184
- DebugSections (oh, debug_abbrev, debug_aranges, debug_frame, debug_info,
202
+ Sect = Union{map (typeof, [debug_abbrev, debug_aranges, debug_frame, debug_info,
203
+ debug_line, debug_loc, debug_macinfo, debug_pubnames, debug_ranges,
204
+ debug_str, debug_types])... }
205
+ DebugSections {T,Sect} (oh, debug_abbrev, debug_aranges, debug_frame, debug_info,
185
206
debug_line, debug_loc, debug_macinfo, debug_pubnames, debug_ranges,
186
207
debug_str, debug_types)
187
208
end
@@ -310,4 +331,12 @@ read{T<:ObjectHandle}(oh::T, args...) = read(oh.io,args...)
310
331
function getSectionLoadAddress
311
332
end
312
333
334
+ immutable LOIByName
335
+ addrs:: Dict{Symbol, UInt64}
336
+ end
337
+ getSectionLoadAddress (LOI:: LOIByName , x:: Union{Symbol, AbstractString} ) =
338
+ LOI. addrs[symbol (x)]
339
+ getSectionLoadAddress (LOI:: LOIByName , sec) =
340
+ getSectionLoadAddress (LOI, bytestring (sectionname (sec)))
341
+
313
342
end # module
0 commit comments