Exemple #1
0
// This testcase put IRBuilder in the heap
TEST_F( LinkerTest, plasma_twice_irbuilder_heap) {

    Initialize();
    Linker linker;

    ///< --mtriple="armv7-none-linux-gnueabi"
    LinkerConfig config1("armv7-none-linux-gnueabi");

    LinkerScript script1;
    /// -L=${TOPDIR}/test/libs/ARM/Android/android-14
    Path search_dir(TOPDIR);
    search_dir.append("test/libs/ARM/Android/android-14");
    script1.directories().insert(search_dir);

    /// To configure linker before setting options. Linker::config sets up
    /// default target-dependent configuration to LinkerConfig.
    linker.emulate(script1, config1);

    config1.setCodeGenType(LinkerConfig::DynObj);  ///< --shared
    config1.options().setSOName("libplasma.once.so");   ///< --soname=libplasma.twice.so
    config1.options().setBsymbolic(false);              ///< -Bsymbolic

    Module module1("libplasma.once.so", script1);
    IRBuilder *builder1 = new IRBuilder(module1, config1);

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtbegin_so.o
    Path crtbegin(search_dir);
    crtbegin.append("crtbegin_so.o");
    builder1->ReadInput("crtbegin", crtbegin);

    /// ${TOPDIR}/test/Android/Plasma/ARM/plasma.o
    Path plasma(TOPDIR);
    plasma.append("test/Android/Plasma/ARM/plasma.o");
    builder1->ReadInput("plasma", plasma);

    // -lm -llog -ljnigraphics -lc
    builder1->ReadInput("m");
    builder1->ReadInput("log");
    builder1->ReadInput("jnigraphics");
    builder1->ReadInput("c");

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtend_so.o
    Path crtend(search_dir);
    crtend.append("crtend_so.o");
    builder1->ReadInput("crtend", crtend);

    if (linker.link(module1, *builder1)) {
        linker.emit("libplasma.once.so"); ///< -o libplasma.so
    }

    // Can not delete builder until emit the output. Dynamic string table
    // needs the file name of the input files, and the inputs' life is
    // controlled by IRBuilder
    delete builder1;

    Finalize();

    linker.reset();

    Initialize();

    ///< --mtriple="armv7-none-linux-gnueabi"
    LinkerConfig config2("armv7-none-linux-gnueabi");

    LinkerScript script2;
    /// -L=${TOPDIR}/test/libs/ARM/Android/android-14
    script2.directories().insert(search_dir);

    /// To configure linker before setting options. Linker::config sets up
    /// default target-dependent configuration to LinkerConfig.
    linker.emulate(script2, config2);

    config2.setCodeGenType(LinkerConfig::DynObj);  ///< --shared
    config2.options().setSOName("libplasma.twice.so");   ///< --soname=libplasma.twice.exe
    config2.options().setBsymbolic();              ///< -Bsymbolic

    Module module2("libplasma.so", script2);
    IRBuilder* builder2 = new IRBuilder(module2, config2);

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtbegin_so.o
    builder2->ReadInput("crtbegin", crtbegin);

    /// ${TOPDIR}/test/Android/Plasma/ARM/plasma.o
    builder2->ReadInput("plasma", plasma);

    // -lm -llog -ljnigraphics -lc
    builder2->ReadInput("m");
    builder2->ReadInput("log");
    builder2->ReadInput("jnigraphics");
    builder2->ReadInput("c");

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtend_so.o
    builder2->ReadInput("crtend", crtend);

    if (linker.link(module2, *builder2)) {
        linker.emit("libplasma.twice.so"); ///< -o libplasma.exe
    }

    delete builder2;
    Finalize();
}
Exemple #2
0
// The outputs generated without -Bsymbolic usually have more relocation
// entries than the outputs generated with -Bsymbolic. This testcase generates
// output with -Bsymbolic first, then generate the same output without -Bsymbolic.
// By this way, we can make sure symbols and relocations are cleaned between
// two linkings.
TEST_F( LinkerTest, plasma_twice) {

    Initialize();
    Linker linker;

    ///< --mtriple="armv7-none-linux-gnueabi"
    LinkerConfig config1("armv7-none-linux-gnueabi");

    LinkerScript script1;
    /// -L=${TOPDIR}/test/libs/ARM/Android/android-14
    Path search_dir(TOPDIR);
    search_dir.append("test/libs/ARM/Android/android-14");
    script1.directories().insert(search_dir);

    /// To configure linker before setting options. Linker::config sets up
    /// default target-dependent configuration to LinkerConfig.
    linker.emulate(script1, config1);

    config1.setCodeGenType(LinkerConfig::DynObj);  ///< --shared
    config1.options().setSOName("libplasma.once.so");   ///< --soname=libplasma.twice.so
    config1.options().setBsymbolic(false);              ///< -Bsymbolic

    Module module1("libplasma.once.so", script1);
    IRBuilder builder1(module1, config1);

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtbegin_so.o
    Path crtbegin(search_dir);
    crtbegin.append("crtbegin_so.o");
    builder1.ReadInput("crtbegin", crtbegin);

    /// ${TOPDIR}/test/Android/Plasma/ARM/plasma.o
    Path plasma(TOPDIR);
    plasma.append("test/Android/Plasma/ARM/plasma.o");
    builder1.ReadInput("plasma", plasma);

    // -lm -llog -ljnigraphics -lc
    builder1.ReadInput("m");
    builder1.ReadInput("log");
    builder1.ReadInput("jnigraphics");
    builder1.ReadInput("c");

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtend_so.o
    Path crtend(search_dir);
    crtend.append("crtend_so.o");
    builder1.ReadInput("crtend", crtend);

    if (linker.link(module1, builder1)) {
        linker.emit("libplasma.once.so"); ///< -o libplasma.so
    }

    Finalize();

    linker.reset();

    Initialize();

    ///< --mtriple="armv7-none-linux-gnueabi"
    LinkerConfig config2("armv7-none-linux-gnueabi");

    LinkerScript script2;
    /// -L=${TOPDIR}/test/libs/ARM/Android/android-14
    script2.directories().insert(search_dir);

    /// To configure linker before setting options. Linker::config sets up
    /// default target-dependent configuration to LinkerConfig.
    linker.emulate(script2, config2);

    config2.setCodeGenType(LinkerConfig::DynObj);  ///< --shared
    config2.options().setSOName("libplasma.twice.so");   ///< --soname=libplasma.twice.exe
    config2.options().setBsymbolic();              ///< -Bsymbolic

    Module module2("libplasma.so", script2);
    IRBuilder builder2(module2, config2);

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtbegin_so.o
    builder2.ReadInput("crtbegin", crtbegin);

    /// ${TOPDIR}/test/Android/Plasma/ARM/plasma.o
    builder2.ReadInput("plasma", plasma);

    // -lm -llog -ljnigraphics -lc
    builder2.ReadInput("m");
    builder2.ReadInput("log");
    builder2.ReadInput("jnigraphics");
    builder2.ReadInput("c");

    /// ${TOPDIR}/test/libs/ARM/Android/android-14/crtend_so.o
    builder2.ReadInput("crtend", crtend);

    if (linker.link(module2, builder2)) {
        linker.emit("libplasma.twice.so"); ///< -o libplasma.exe
    }

    Finalize();
}