Skip to content

Commit 76b59ec

Browse files
authored
Merge pull request #6 from Keno/kf/isdynamic
Add an isdynamic function
2 parents 98d7b32 + e32be12 commit 76b59ec

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

src/Abstract/ObjectHandle.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export ObjectHandle,
33
readmeta,
44
seek, seekstart, skip, start, iostream, position, read, readuntil, eof,
5-
endianness, is64bit, isrelocatable, isexecutable, islibrary,
5+
endianness, is64bit, isrelocatable, isexecutable, islibrary, isdynamic,
66
mangle_section_name, mangle_symbol_name, handle, header, format_string,
77
section_header_offset, section_header_size, section_header_type,
88
segment_header_offset, segment_header_size, segment_header_type,
@@ -49,6 +49,7 @@ where `oh <: COFFHandle`).
4949
- *isrelocatable()*
5050
- *isexecutable()*
5151
- *islibrary()*
52+
- *isdynamic()*
5253
- *mangle_section_name()*
5354
- *mangle_symbol_name()*
5455
- handle()
@@ -214,6 +215,13 @@ Returns `true` if the given `ObjectHandle` represents a shared library
214215
"""
215216
@mustimplement islibrary(oh::ObjectHandle)
216217

218+
"""
219+
isdynamic(oh::ObjectHandle)
220+
221+
Returns `true` if the given `ObjectHandle` makes use of dynamic linking.
222+
"""
223+
@mustimplement isdynamic(oh::ObjectHandle)
224+
217225
"""
218226
mangle_section_name(oh::ObjectHandle, name::AbstractString)
219227

src/COFF/COFFHandle.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ is64bit(oh::COFFHandle) = coff_header_is64bit(header(oh))
7878
isrelocatable(oh::COFFHandle) = isrelocatable(header(oh))
7979
isexecutable(oh::COFFHandle) = isexecutable(header(oh))
8080
islibrary(oh::COFFHandle) = islibrary(header(oh))
81+
isdynamic(oh::COFFHandle) = !isempty(find(Sections(oh), [".idata"]))
8182
mangle_section_name(oh::COFFHandle, name::AbstractString) = string(".", name)
8283
function mangle_symbol_name(oh::COFFHandle, name::AbstractString)
8384
# sob
@@ -109,4 +110,4 @@ function strtab_offset(oh::H) where {H <: COFFHandle}
109110
end
110111

111112
### Misc. stuff
112-
path(oh::COFFHandle) = oh.path
113+
path(oh::COFFHandle) = oh.path

src/ELF/ELFHandle.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ is64bit(oh::ELFHandle) = elf_internal_is64bit(oh.ei)
7272
isrelocatable(oh::ELFHandle) = header(oh).e_type == ET_REL
7373
isexecutable(oh::ELFHandle) = header(oh).e_type == ET_EXEC
7474
islibrary(oh::ELFHandle) = header(oh).e_type == ET_DYN
75+
isdynamic(oh::ELFHandle) = !isempty(find(Sections(oh), ".dynamic"))
7576
mangle_section_name(oh::ELFHandle, name::AbstractString) = string(".", name)
7677
mangle_symbol_name(oh::ELFHandle, name::AbstractString) = name
7778
format_string(::Type{H}) where {H <: ELFHandle} = "ELF"

src/MachO/MachOHandle.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ is64bit(oh::MachOHandle) = macho_is64bit(header(oh).magic)
4040
isrelocatable(oh::MachOHandle) = header(oh).filetype == MH_OBJECT
4141
isexecutable(oh::MachOHandle) = header(oh).filetype == MH_EXECUTE
4242
islibrary(oh::MachOHandle) = header(oh).filetype == MH_DYLIB
43+
isdynamic(oh::MachOHandle) = !isempty(find(MachOLoadCmds(oh), [MachOLoadDylibCmd]))
4344
mangle_section_names(oh::MachOHandle, name) = string("__", name)
4445
mangle_symbol_name(oh::MachOHandle, name::AbstractString) = string("_", name)
4546
format_string(::Type{H}) where {H <: MachOHandle} = "MachO"

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function test_libfoo_and_fooifier(fooifier_path, libfoo_path)
3838
# Ensure these are the kinds of files we thought they were
3939
@test isexecutable(oh_exe)
4040
@test islibrary(oh_lib)
41+
@test isdynamic(oh_exe) && isdynamic(oh_lib)
4142
end
4243

4344

@@ -154,4 +155,4 @@ test_libfoo_and_fooifier("./mac64/fooifier", "./mac64/libfoo.dylib")
154155

155156
# Run COFF tests
156157
test_libfoo_and_fooifier("./win32/fooifier.exe", "./win32/libfoo.dll")
157-
test_libfoo_and_fooifier("./win64/fooifier.exe", "./win64/libfoo.dll")
158+
test_libfoo_and_fooifier("./win64/fooifier.exe", "./win64/libfoo.dll")

0 commit comments

Comments
 (0)