Skip to content

Commit

Permalink
Merge pull request #6 from Keno/kf/isdynamic
Browse files Browse the repository at this point in the history
Add an isdynamic function
  • Loading branch information
staticfloat authored Dec 6, 2017
2 parents 98d7b32 + e32be12 commit 76b59ec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/Abstract/ObjectHandle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export ObjectHandle,
readmeta,
seek, seekstart, skip, start, iostream, position, read, readuntil, eof,
endianness, is64bit, isrelocatable, isexecutable, islibrary,
endianness, is64bit, isrelocatable, isexecutable, islibrary, isdynamic,
mangle_section_name, mangle_symbol_name, handle, header, format_string,
section_header_offset, section_header_size, section_header_type,
segment_header_offset, segment_header_size, segment_header_type,
Expand Down Expand Up @@ -49,6 +49,7 @@ where `oh <: COFFHandle`).
- *isrelocatable()*
- *isexecutable()*
- *islibrary()*
- *isdynamic()*
- *mangle_section_name()*
- *mangle_symbol_name()*
- handle()
Expand Down Expand Up @@ -214,6 +215,13 @@ Returns `true` if the given `ObjectHandle` represents a shared library
"""
@mustimplement islibrary(oh::ObjectHandle)

"""
isdynamic(oh::ObjectHandle)
Returns `true` if the given `ObjectHandle` makes use of dynamic linking.
"""
@mustimplement isdynamic(oh::ObjectHandle)

"""
mangle_section_name(oh::ObjectHandle, name::AbstractString)
Expand Down
3 changes: 2 additions & 1 deletion src/COFF/COFFHandle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ is64bit(oh::COFFHandle) = coff_header_is64bit(header(oh))
isrelocatable(oh::COFFHandle) = isrelocatable(header(oh))
isexecutable(oh::COFFHandle) = isexecutable(header(oh))
islibrary(oh::COFFHandle) = islibrary(header(oh))
isdynamic(oh::COFFHandle) = !isempty(find(Sections(oh), [".idata"]))
mangle_section_name(oh::COFFHandle, name::AbstractString) = string(".", name)
function mangle_symbol_name(oh::COFFHandle, name::AbstractString)
# sob
Expand Down Expand Up @@ -109,4 +110,4 @@ function strtab_offset(oh::H) where {H <: COFFHandle}
end

### Misc. stuff
path(oh::COFFHandle) = oh.path
path(oh::COFFHandle) = oh.path
1 change: 1 addition & 0 deletions src/ELF/ELFHandle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ is64bit(oh::ELFHandle) = elf_internal_is64bit(oh.ei)
isrelocatable(oh::ELFHandle) = header(oh).e_type == ET_REL
isexecutable(oh::ELFHandle) = header(oh).e_type == ET_EXEC
islibrary(oh::ELFHandle) = header(oh).e_type == ET_DYN
isdynamic(oh::ELFHandle) = !isempty(find(Sections(oh), ".dynamic"))
mangle_section_name(oh::ELFHandle, name::AbstractString) = string(".", name)
mangle_symbol_name(oh::ELFHandle, name::AbstractString) = name
format_string(::Type{H}) where {H <: ELFHandle} = "ELF"
Expand Down
1 change: 1 addition & 0 deletions src/MachO/MachOHandle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ is64bit(oh::MachOHandle) = macho_is64bit(header(oh).magic)
isrelocatable(oh::MachOHandle) = header(oh).filetype == MH_OBJECT
isexecutable(oh::MachOHandle) = header(oh).filetype == MH_EXECUTE
islibrary(oh::MachOHandle) = header(oh).filetype == MH_DYLIB
isdynamic(oh::MachOHandle) = !isempty(find(MachOLoadCmds(oh), [MachOLoadDylibCmd]))
mangle_section_names(oh::MachOHandle, name) = string("__", name)
mangle_symbol_name(oh::MachOHandle, name::AbstractString) = string("_", name)
format_string(::Type{H}) where {H <: MachOHandle} = "MachO"
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function test_libfoo_and_fooifier(fooifier_path, libfoo_path)
# Ensure these are the kinds of files we thought they were
@test isexecutable(oh_exe)
@test islibrary(oh_lib)
@test isdynamic(oh_exe) && isdynamic(oh_lib)
end


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

# Run COFF tests
test_libfoo_and_fooifier("./win32/fooifier.exe", "./win32/libfoo.dll")
test_libfoo_and_fooifier("./win64/fooifier.exe", "./win64/libfoo.dll")
test_libfoo_and_fooifier("./win64/fooifier.exe", "./win64/libfoo.dll")

0 comments on commit 76b59ec

Please sign in to comment.