EzDevInfo.com

Loader

Small utility dependency loader for scripts and css files, loads non-blocking in parallel, caches files in HTML5 Local Storage for ULTRA FAST LOADING

VA (Virtual Adress) & RVA (Relative Virtual Address)

A file that is given as input to the linker is called Object File. The linker produces an Image file, which in turn is used as input by the loader.

A blurb from "Microsoft Portable Executable and Common Object File Format Specification"

RVA (relative virtual address). In an image file, the address of an item after it is loaded into memory, with the base address of the image file subtracted from it. The RVA of an item almost always differs from its position within the file on disk (file pointer).

In an object file, an RVA is less meaningful because memory locations are not assigned. In this case, an RVA would be an address within a section (described later in this table), to which a relocation is later applied during linking. For simplicity, a compiler should just set the first RVA in each section to zero.

VA (virtual address). Same as RVA, except that the base address of the image file is not subtracted. The address is called a “VA” because Windows creates a distinct VA space for each process, independent of physical memory. For almost all purposes, a VA should be considered just an address. A VA is not as predictable as an RVA because the loader might not load the image at its preferred location.

Even after reading this, I still don't get it. I've lot of questions. Can any one explain it in a practical way. Please stick to terminology of Object File & Image File as stated.

All I know about addresses, is that

  • Neither in the Object File nor in the Image File, we don't know the exact memory locations so,
  • Assembler while generating Object File computes addresses relative to sections .data & .text (for function names).
  • Linker taking multiple object files as input generates one Image file. While generating, it first merges all the sections of each object file and while merging it recomputes the address offsets again relative to each section. And, there is nothing like global offsets.

If there is some thing wrong in what I know, please correct me.

EDIT:

After reading answer given Francis, I'm clear about whats Physical Address, VA & RVA and what are the relation between them.

RVAs of all variables&methods must be computed by the Linker during relocation. So, (the value of RVA of a method/variable) == (its offset from the beginning of the file)? must been true. But surprisingly, its not. Why so?

I checked this by using PEView on c:\WINDOWS\system32\kernel32.dll and found that:

  1. RVA & FileOffset are same till the beginning of Sections.(.text is the first section in this dll).
  2. From the beginning of .text through .data,.rsrc till the last byte of last section (.reloc) RVA & FileOffset are different. & also the RVA of first byte of the first section is "always" being shown as 0x1000
  3. Interesting thing is that bytes of each section are continuous in FileOffset. I mean another section begins at the next byte of a section's last byte. But if I see the same thing in RVA, these is a huge gap in between RVAs of last byte of a section and first byte of next section.

My Guess:

  1. All, the bytes of data that were before the first (.text here) section are "not" actually loaded into VA space of the process, these bytes of data are just used to locate & describe these sections. They can be called, "meta section data".

    Since they are not loaded into VA space of process. the usage of the term RVA is also meaningless this is the reason why RVA == FileOffset for these bytes.

  2. Since,

    • RVA term is valid for only those bytes which will be actually loaded into the VA space.
    • the bytes of .text, .data, .rsrc, .reloc are such bytes.
    • Instead of starting from RVA 0x00000 PEView software is starting it from 0x1000.
  3. I cannot understand why the 3rd observation. I cannot explain.


Source: (StackOverflow)

What is compiler, linker, loader?

I wanted to know in depth meaning and working of compiler, linker and loader. With reference to any language preferably c++.


Source: (StackOverflow)

Advertisements

Dex Loader Unable to execute Multiple dex files define

Okay, now i'm really stuck here. I don't know what to do, where to go or ANYTHING!

I have been trying to uninstall, reinstall, both SDK and Eclipse-versions, trying to Google this out, but nu-uh... Nothing!!!

I CAN run my app in emulator, but i cant EXPORT it...

[2011-10-07 16:35:30 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/dreamhawk/kalori/DataBaseHelper;

this is dataBaseHelper

package com.dreamhawk.kalori;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;



public class DataBaseHelper extends SQLiteOpenHelper {

    // The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.dreamhawk.kalori/databases/";

    private static String DB_NAME = "livsmedel_db";
    private DataBaseHelper myDBHelper;
    private SQLiteDatabase myDb;

    private final Context myContext;

    private static final String DATABASE_TABLE = "Livsmedel";
    public static String DB_FILEPATH = "/data/data/com.dreamhawk.kalori/databases/lifemedel_db";
    public static final String KEY_TITLE = "Namn";
    public static final String KEY_BODY = "Kcal";
    public static final String KEY_ROWID = "_id";
    private static final int DATABASE_VERSION = 2;

    /**
     * Constructor Takes and keeps a reference of the passed context in order to
     * access to the application assets and resources.
     * 
     * @param context
     */
    public DataBaseHelper(Context context) {

        super(context, DB_NAME, null, 1);
        this.myContext = context;

        // checking database and open it if exists
        if (checkDataBase()) {
            openDataBase();
        } else {
            try {
                this.getReadableDatabase();
                createDatabase();
                this.close();
                openDataBase();

            } catch (IOException e) {
                throw new Error("Error copying database");
            }
            Toast.makeText(context, "Livsmedelsdatabasen importerad",
                    Toast.LENGTH_LONG).show();
        }

    }

    private boolean checkDataBase() {
        SQLiteDatabase checkDB = null;
        boolean exist = false;
        try {
            String dbPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(dbPath, null,
                    SQLiteDatabase.OPEN_READONLY);
        } catch (SQLiteException e) {
            Log.v("db log", "database does't exist");
        }

        if (checkDB != null) {
            exist = true;
            checkDB.close();
        }
        return exist;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // db.execSQL(DATABASE_CREATE);
    }

     @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

           Log.w("Kalori", "Upgrading database from version " + oldVersion + " to "
               + newVersion + ", which will destroy all old data");
           db.execSQL("DROP TABLE IF EXISTS Livsmedel");
           onCreate(db);

       }

    public DataBaseHelper open() throws SQLException {
        myDBHelper = new DataBaseHelper(myContext);
        myDb = myDBHelper.getWritableDatabase();
        return this;
    }

    public void createDatabase() throws IOException {

        InputStream assetsDB = myContext.getAssets().open("livsmedel_db");
        // OutputStream dbOut = new FileOutputStream(DB_PATH);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream dbOut = new FileOutputStream(outFileName);

        Log.d("DH", "index=" + assetsDB);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = assetsDB.read(buffer)) > 0) {
            dbOut.write(buffer, 0, length);
        }

        dbOut.flush();
        dbOut.close();
        assetsDB.close();
    }

    public Cursor fetchAllNotes() {

        return myDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE,
                KEY_BODY }, null, null, null, null, null);
    }

    public void openDataBase() throws SQLException {
        String dbPath = DB_PATH + DB_NAME;
        myDb = SQLiteDatabase.openDatabase(dbPath, null,
                SQLiteDatabase.OPEN_READWRITE);
    }

}

I suspect:

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

But I don't know what to do... Please help !!! :'(


Source: (StackOverflow)

Why are static and dynamic linkable libraries different?

If both of them contain compiled code, why can't we load the "static" files at runtime and why can't we link with the dynamic libraries at compile time? Why is there a need for separate formats to contain "standalone" code? What needs to be stored in either one that warrants the difference?


Source: (StackOverflow)

Android: LoaderCallbacks.OnLoadFinished called twice

I noticed strange situation using Android Loaders and Fragments. When I invoke LoaderManager.initLoader() after orientation change onLoadFinished is not called (although documentation suggests I should be prepared for this) but it is called twice after this. Here is link to post in google groups which describe the same situation https://groups.google.com/forum/?fromgroups#!topic/android-developers/aA2vHYxSskU . I wrote sample application in which I only init simple Loader in Fragment.onActivityCreated() to check if this happens and it does. Anyone noticed this?


Source: (StackOverflow)

load-time ELF relocation

I am writing a simple user-space ELF loader under Linux (why? for 'fun'). My loader at the moment is quite simple and is designed to load only statically-linked ELF files containing position-independent code.

Normally, when a program is loaded by the kernel's ELF loader, it is loaded into its own address space. As such, the data segment and code segment can be loaded at the correct virtual address as specified in the ELF segments.

In my case, however, I am requesting addresses from the kernel via mmap, and may or may not get the addresses requested in the ELF segments. This is not a problem for the code segment since it is position independent. However, if the data segment is not loaded at the expected address, code will not be able to properly reference anything stored in the data segment.

Indeed, my loader appears to work fine with a simple assembly executable that does not contain any data. But as soon as I add a data segment and reference it, the executable fails to run correctly or SEGFAULTs.

How, if possible, can I fixup any references to the data segment to point to the correct place? Is there a relocation section stored in the (static) ELF file for this purpose?


Source: (StackOverflow)

Linking : .a, .lib and .def files

I am building a dll from assembly on Windows using the GNU binutils.

I know that the dll can be either loaded when the executable is loaded or at run-time (using the LoadLibrary api call).

For load-time loading, I seem to be only needing the dll file : no .a, .lib or .def file is needed. I wondered what these file format represent and what purpose do they serve.

What I know and some specific questions :

  • .a is the extension generally used for static library on Unix. .a files are generated with the --out-implib option of GNU ld. It is said to be an "import library", fair enough. The question is then "What good is an import library to me if I don't need it when linking ?"

  • .lib is the extension used for static library on Windows, and according to wikipedia, is also used as "import library" under windows, so I strongly suspect they're just another name for what the binutils call .a files. True/false ?

  • All pages I can find points that .def files list the exported symbol of the dll. Isn't that somewhat similar to what an "import library" is supposed to do ?

  • Also, I read here that using .def files is an alternative to manually specifying exports in the source file (which I did). But I also remember reading (cannot find reference back) .def file supply an index (ordinal) into the exported symbols, allowing for faster run-time loading. Is that so ?


Source: (StackOverflow)

How to change your XCode iTunes Connect login?

I am using several accounts to manage my customers iPhone/iPad applications. Therefore I need to connect to iTunes Connect with different logins. How can I change the login in XCode or Application Loader? It is always set to one default value that I probably entered the first time XCode was started.

When it comes to validating or submitting an application using the XCode Organizer I start to hate Apple for what they have done to use developers. In those situations I feel like a worm inside an Apple, pretty lost. The problem is that clicking on one of those buttons (Validate... or Submit...) is NOT giving ANY kind of feedback except in rare occations. The only way to see what is happening is using Console to see XCode log messages.


Source: (StackOverflow)

MEF: "Unable to load one or more of the requested types. Retrieve the LoaderExceptions for more information"

Scenario: I am using Managed Extensibility Framework to load plugins (exports) at runtime based on an interface contract defined in a separate dll. In my Visual Studio solution, I have 3 different projects: The host application, a class library (defining the interface - "IPlugin") and another class library implementing the interface (the export - "MyPlugin.dll").

The host looks for exports in its own root directory, so during testing, I build the whole solution and copy Plugin.dll from the Plugin class library bin/release folder to the host's debug directory so that the host's DirectoryCatalog will find it and be able to add it to the CompositionContainer. Plugin.dll is not automatically copied after each rebuild, so I do that manually each time I've made changes to the contract/implementation.

However, a couple of times I've run the host application without having copied (an updated) Plugin.dll first, and it has thrown an exception during composition:

Unable to load one or more of the requested types. Retrieve the LoaderExceptions for more information

This is of course due to the fact that the Plugin.dll it's trying to import from implements a different version of IPlugin, where the property/method signatures don't match. Although it's easy to avoid this in a controlled and monitored environment, by simply avoiding (duh) obsolete IPlugin implementations in the plugin folder, I cannot rely on such assumptions in the production environment, where legacy plugins could be encountered.

The problem is that this exception effectively botches the whole Compose action and no exports are imported. I would have preferred that the mismatching IPlugin implementations are simply ignored, so that other exports in the catalog(s), implementing the correct version of IPlugin, are still imported.

Is there a way to accomplish this? I'm thinking either of several potential options:

  • There is a flag to set on the CompositionContainer ("ignore failing imports") prior to or when calling Compose
  • There is a similar flag to specify on the <ImportMany()> attribute
  • There is a way to "hook" on to the iteration process underlying Compose(), and be able to deal with each (failed) import individually
  • Using strong name signing to somehow only look for imports implementing the current version of IPlugin

Ideas?


Source: (StackOverflow)

Where to find Application Loader app in Mac?

I have downloaded applicationloader_1.3.dmg and installed in the destination Macintosh HD.

The messages show The installation was successfully done. But, there is the ApplicationLoader app that doesn't appear anywhere.

How to install and get the Applicationloader app in Application->Utility folder?

I'm using Mac OSX version 10.6.8.


Source: (StackOverflow)

Can es6's module loader also load assets (html/css/...)

ES6's modules are based on a flexible loader architecture (although the standard is not final, so ...).

Does this mean ES6's loader, based on system.js, can load all assets? I.e. CSS, HTML, Images, Text, .. files of any sort?

I ask because I'm starting to use WebComponents & Polymer which have their own HTML import, and implementing them with ES6, which has its own import/loader (system.js).


Source: (StackOverflow)

How to have aliased variables in shared libraries?

I want to put two aliased variables in a library so that the application code can use either name. But I find it can be done in a static library but not in a shared library. Here is my experiment. I did it on an X86 Linux machine with gcc compiler.

test.c -- the application code

#include <stdio.h>   
extern int myfunc(int, int);
extern int myglob;
extern int myglob_;

int main(int argc, const char* argv[])
{
    printf("&myglob = %p\n", &myglob);
    printf("&myglob_ = %p\n", &myglob_); 
    myglob = 1234;
    printf("myglob = %d\n", myglob);
    printf("myglob_ = %d\n", myglob_);

    return myfunc(argc, argc);
}

my.c -- the library code

int myglob = 42;
extern int myglob_ __attribute__ ((alias("myglob")));   
int myfunc(int a, int b)
{
    myglob += a;
    return b + myglob;
}

Build and run with static library. We can see myglob and myglob_ are indeed aliased.

gcc -c my.c
ar rsc libmy.a my.o
gcc -o test test.c -L. -lmy
./test
&myglob = 0x601040
&myglob_ = 0x601040
myglob = 1234
myglob_ = 1234

Build and run with shared library. We can see myglob and myglob_ point to different addresses and basically are two distinct variables.

gcc -fPIC -c my.c
gcc -shared -o libmy.so my.o
gcc -o test test.c -L. -lmy
./test
&myglob = 0x601048
&myglob_ = 0x601050
myglob = 1234
myglob_ = 42

So, why do aliased symbols not work in shared library? How to fix it? Thanks.

=============Follow up===============

I tried to build a position-independent executable using "gcc -o test test.c -L. -lmy -fPIC". With this, myglob and myglob_ are indeed aliased with the shared library. However, this approach does not work in the background problem which spawned the question. I list the problem and the reason why I need it. (Note that I have to use F77 common blocks in my project)

A Fortran header file

! myf.h
common /myblock/ myglob
save myblock

Init routine in Fortran

! initf.f90
subroutine initf()
    integer myglob
    common /myblock/  myglob
    call initc(myglob)
end subroutine

Init routine in C

// initc.c
#include <stdio.h>
extern void initf_(); 
void init() { initf_(); }
extern void init_() __attribute__((alias("init")));
void initc_(int *pmyglob) { printf("&myglob in library = %p\n", pmyglob); }

Fortran library wrapper in C

// my.c
#include <stdio.h>
extern void myfunc(int *pmyglob)
{
    printf("&myglob in app     = %p\n", pmyglob);
    // May call a Fortran subroutine. That's why myfunc() is a wrapper
}
extern void myfunc_(int *) __attribute__ ((alias("myfunc")));
typedef struct myblock_t_ {
    int idx;
} myblock_t;
myblock_t myblock __attribute__((aligned(16))) = {0};
extern myblock_t myblock_ __attribute__((alias("myblock")));

Application in Fortran

! test.f90
program main
    include 'myf.h'
    call init();
    call myfunc(myglob);
end program

Build a shared library libmy.so and use it

gfortran -fPIC -c initf.f90
gcc -fPIC -c initc.c
gcc -fPIC -c my.c
gcc -fPIC -shared -o libmy.so initf.o initc.o my.o
gfortran -fPIC -o test test.f90 -L. -lmy
./test
&myglob in library = 0x601070
&myglob in app     = 0x601070

Suppose we want the library to be portable, and the application is compiled by another Fortran compiler with a different name mangling convention (I use gfortran --fno-underscoring to mimic that)

// libmy.so is built as same as above
...
gfortran -fPIC -fno-underscoring  -o test test.f90 -L. -lmy
./test
&myglob in library = 0x7fb3c19d9060
&myglob in app     = 0x601070

Any suggestions? Thanks.


Source: (StackOverflow)

Difference between load-time dynamic linking and run-time dynamic linking

When loading programs into memory, what is the difference between load-time dynamic linking and run-time dynamic linking?


Source: (StackOverflow)

Linux user-space ELF loader

I need to do a rather unusual thing: manually execute an elf executable. I.e. load all sections into right places, query main() and call it (and cleanup then). Executable will be statically linked, so there will be no need to link libraries. I also control base address, so no worries about possible conflicts.

So, is there are any libraries for that?

I found OSKit and its liboskit_exec, but project seems to be dead since 2002.

I'm OK with taking parts of projects (respecting licenses, of course) and tailoring them to my need, but as I'm quite a noob in the linux world, I dont even know where to find those parts! :)

PS. I need that for ARM platform.

UPD Well, the matter of loading elfs seems to require some good knowledge about it (sigh), so I'm out to read some specs and manuals. And I think I will stick to bionic/linker and libelfsh. Thanks guys!

Summarized findings:


Source: (StackOverflow)

OnLoadFinished() called twice

I'm trying to figure out if I'm doing something wrong with respect to Loaders. I'm using the support library, and I have a Fragment which in onCreate() calls initLoader() setting itself as the LoaderCallbacks, however on a rotation it is receiving the result twice in onLoadFinished(), once as a result of calling init (and it already having the data), and once as a result of FragmentActivity looping through all Loaders in onStart() and delivering the result since it already has the data.

If I only call init once (on first launch of the Fragment), it doesn't set itself as the callback for the Loader so it doesn't receive a call to onLoadFinished at all. It seems as though onLoadFinished should only be called once since some expensive things may be done in onLoadFinished() (such as clearing list adapters, etc.), so I'm just trying to figure out if this is a bug or if I am just calling init at the wrong time or something else.

Anyone have any insight to this issue?


Source: (StackOverflow)