Verizon Fios Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 29 January 2013

How to build Python-4-Android for the x86

Posted on 12:57 by Unknown
Currently the Py4A project only compiles for the ARM architecture.

The following patch for the python-build sub-directory allows you to cross-compile Py4A for the x86 architecture. The patch consists in:
  1. Adding a set of new files to support the x86 architecture (including creating a new libffi/linux-x86/ directory):

    libffi/linux-x86/ffi.h
    libffi/linux-x86/fficonfig.h
    setup-x86.cfg
  2. changing the build.sh script to accept a new parameter - the Android ABI (for example 'armeabi' or 'x86') - so that the script can call

    ndk-build APP_ABI:=x86

    to trigger the cross-compilation for the x86 processor;
  3. changing the build.py script to parametrize the GCC strip command and the selection of the setup.cfg configuration file based on the input ABI;
  4. changing the libffi/Android.mk makefile to select the right set of source files based on the input ABI;
  5. changing the libffi/include/ffi_real.h header file to redefine FFI_TYPE_LONGDOUBLE to 4;
  6. changing the openssl/crypto/Android.mk and openssl/ssl/Android.mk makefiles to strip down the openssl library with only the bare minimum set that allows you to cross-compile the source code;
  7. changing the  python/jni/modules.mk makefile to add the -fno-stack-protector compiler and linker option when building the _socket module and exclude the openssl module.
After applying the patch, to cross-compile Py4A for the x86 architecture you should run the following:

$ cd python-build
$ ./build.sh x86

Binaries for the x86 can be downloaded here:


  • python_extras_r14.zip
  • python-lib_r16.zip
  • python_r16.zip
  • python_scripts_r13.zip



--- orig/python/jni/modules.mk    2013-01-21 14:39:56.000000000 -0500
+++ python/jni/modules.mk    2013-01-29 14:58:52.922096000 -0500
@@ -58,7 +58,7 @@ $(call build-module,  syslog ,  Modules/
 $(call build-module,  audioop ,  Modules/audioop.c )
 $(call build-module,  imageop ,  Modules/imageop.c )
 $(call build-module,  _csv ,  Modules/_csv.c )
-$(call build-module,  _socket ,  Modules/socketmodule.c, libc, -lc, -nostdlib )
+$(call build-module,  _socket ,  Modules/socketmodule.c, libc, -lc -fno-stack-protector, -nostdlib -fno-stack-protector )
 $(call build-module,  _sha ,  Modules/shamodule.c )
 $(call build-module,  _md5 ,  Modules/md5module.c Modules/md5.c )
 $(call build-module,  _sha256 ,  Modules/sha256module.c )
@@ -125,6 +125,7 @@ include $(BUILD_SHARED_LIBRARY)
 
 #$(call build-module,  _ssl ,  Modules/_ssl.c, ssl crypto )
 
+ifneq ($(APP_ABI), x86)
 $(call import-module, openssl)
 LOCAL_PATH :=  $(PYTHON_SRC_PATH)
 LOCAL_C_INCLUDES += $(PYTHON_SRC_PATH) $(PYTHON_SRC_PATH)/Include $(OPENSSL)/include $(OPENSSL)
@@ -133,6 +134,7 @@ LOCAL_MODULE_FILENAME := _ssl
 LOCAL_SRC_FILES := Modules/_ssl.c
 LOCAL_SHARED_LIBRARIES := libpython2.6 libcrypto libssl
 include $(BUILD_SHARED_LIBRARY)
+endif
 
 
 $(call import-module, libffi)
--- orig/setup-x86.cfg    1969-12-31 19:00:00.000000000 -0500
+++ setup-x86.cfg    2013-01-28 16:09:49.004463929 -0500
@@ -0,0 +1,2 @@
+[bdist_egg]
+plat-name=linux-x86
--- orig/openssl/ssl/Android.mk    2013-01-21 14:42:17.000000000 -0500
+++ openssl/ssl/Android.mk    2013-01-28 16:33:35.563643087 -0500
@@ -7,6 +7,10 @@ local_c_includes := \
 
 include $(CLEAR_VARS)
 
+ifeq ($(APP_ABI), x86)
+LOCAL_SRC_FILES:= \
+    kssl.c
+else
 LOCAL_SRC_FILES:= \
     s2_meth.c \
     s2_srvr.c \
@@ -45,6 +49,7 @@ LOCAL_SRC_FILES:= \
     bio_ssl.c \
     ssl_err.c \
     kssl.c
+endif
 
 include $(LOCAL_PATH)/../android-config.mk
 
--- orig/openssl/crypto/Android.mk    2013-01-21 14:42:08.000000000 -0500
+++ openssl/crypto/Android.mk    2013-01-29 14:49:00.334324159 -0500
@@ -2,27 +2,17 @@ LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
 LOCAL_CFLAGS += -DOPENSSL_BN_ASM_MONT -DAES_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DOPENSSL_NO_STATIC_ENGINE
+ifneq ($(APP_ABI), x86)
 LOCAL_SRC_FILES:= 0.9.9-dev/bn/armv4-mont.s \
                   0.9.9-dev/aes/aes-armv4.s \
                   0.9.9-dev/sha/sha1-armv4-large.s \
                   0.9.9-dev/sha/sha256-armv4.s \
                   0.9.9-dev/sha/sha512-armv4.s
-
 LOCAL_SRC_FILES+= \
-    cryptlib.c \
-    mem.c \
-    mem_clr.c \
     mem_dbg.c \
-    cversion.c \
     dyn_lck.c \
     ex_data.c \
-    tmdiff.c \
     cpt_err.c \
-    ebcdic.c \
-    uid.c \
-    o_time.c \
-    o_str.c \
-    o_dir.c \
     aes/aes_misc.c \
     aes/aes_ecb.c \
     aes/aes_cbc.c \
@@ -474,6 +464,19 @@ LOCAL_SRC_FILES+= \
     ripemd/rmd_dgst.c \
     ripemd/rmd_one.c \
     evp/m_ripemd.c
+endif
+
+LOCAL_SRC_FILES+= \
+    cryptlib.c \
+    mem.c \
+    mem_clr.c \
+    cversion.c \
+    tmdiff.c \
+    ebcdic.c \
+    uid.c \
+    o_time.c \
+    o_str.c \
+    o_dir.c
 
 LOCAL_CFLAGS += -DNO_WINDOWS_BRAINDEATH
 
--- orig/build.py    2013-01-21 14:44:17.000000000 -0500
+++ build.py    2013-01-28 16:19:35.088015089 -0500
@@ -82,6 +82,10 @@ def rm(path):
 
 
 def strip(path):
+  if len(sys.argv) > 1:
+    if sys.argv[1] == "x86":
+      run('i686-linux-android-strip %s' % path)
+    else:
   run('arm-linux-androideabi-strip %s' % path)
 
 
@@ -153,6 +157,12 @@ map(rm, find('output.temp/usr/lib/python
 map(rm, find('output.temp', 'python$', exclude=['setuptools', 'distutils'])[0])
 run("mkdir python", cwd="output.temp/usr")
 run("cp -r %s/python-libs/py4a python" % pwd, cwd="output.temp/usr")
+if len(sys.argv) > 1:
+    if sys.argv[1] == "x86":
+        run("cp %s/setup-x86.cfg ." % pwd, cwd="output.temp/usr")
+    else:
+        run("cp %s/setup.cfg ." % pwd, cwd="output.temp/usr")
+else:
 run("cp %s/setup.cfg ." % pwd, cwd="output.temp/usr")
 run("cp %s/prepare_setuptools.sh setup.sh" % pwd, cwd="output.temp/usr")
 run("cp %s/standalone_python.sh python.sh" % pwd, cwd="output.temp/usr")
--- orig/libffi/include/ffi_real.h    2013-01-21 14:42:35.000000000 -0500
+++ libffi/include/ffi_real.h    2013-01-29 10:27:30.664550823 -0500
@@ -371,8 +371,12 @@ void ffi_call(ffi_cif *cif,
 #if CONF_HAVE_LONG_DOUBLE       // android changed
 #define FFI_TYPE_LONGDOUBLE 4
 #else
+#ifdef x86
+#define FFI_TYPE_LONGDOUBLE 4
+#else
 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
 #endif
+#endif
 #define FFI_TYPE_UINT8      5  
 #define FFI_TYPE_SINT8      6
 #define FFI_TYPE_UINT16     7
--- orig/libffi/Android.mk    2013-01-21 14:42:42.000000000 -0500
+++ libffi/Android.mk    2013-01-28 17:00:21.190897854 -0500
@@ -21,6 +21,17 @@ include $(CLEAR_VARS)
 
 LOCAL_MODULE := ffi
 LOCAL_MODULE_FILENAME :=
+ifeq ($(APP_ABI), x86)
+    LOCAL_SRC_FILES := src/x86/sysv.S \
+    src/x86/ffi.c \
+    src/debug.c \
+    src/java_raw_api.c \
+    src/prep_cif.c \
+    src/raw_api.c \
+    src/types.c
+
+    LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/linux-x86
+else
 LOCAL_SRC_FILES := src/arm/sysv.S \
     src/arm/ffi.c \
     src/debug.c \
@@ -30,6 +41,7 @@ LOCAL_SRC_FILES := src/arm/sysv.S \
     src/types.c
 
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/linux-arm
+endif
 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
 
 $(call __ndk_info, Building libffi)
--- orig/libffi/linux-x86/ffi.h    1969-12-31 19:00:00.000000000 -0500
+++ libffi/linux-x86/ffi.h    2013-01-28 16:24:28.975890002 -0500
@@ -0,0 +1,10 @@
+/*
+ * Copyright 2008 The Android Open Source Project
+ */
+#ifndef LIBFFI_H
+
+#define x86
+#include "../src/x86/ffitarget.h"
+#include "../include/ffi_real.h"
+
+#endif
--- orig/libffi/linux-x86/fficonfig.h    1969-12-31 19:00:00.000000000 -0500
+++ libffi/linux-x86/fficonfig.h    2013-01-28 16:23:04.047926730 -0500
@@ -0,0 +1,160 @@
+/* fficonfig.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+   systems. This function is required for `alloca.c' support on those systems.
+   */
+#undef CRAY_STACKSEG_END
+
+/* Define to 1 if using `alloca.c'. */
+#undef C_ALLOCA
+
+/* Define to the flags needed for the .section .eh_frame directive. */
+#define EH_FRAME_FLAGS "aw"
+
+/* Define this if you want extra debugging. */
+#undef FFI_DEBUG
+
+/* Define this is you do not want support for the raw API. */
+#undef FFI_NO_RAW_API
+
+/* Define this is you do not want support for aggregate types. */
+#undef FFI_NO_STRUCTS
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+#define HAVE_ALLOCA 1
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+#define HAVE_ALLOCA_H 1
+
+/* Define if your assembler supports .cfi_* directives. */
+#undef HAVE_AS_CFI_PSEUDO_OP
+
+/* Define if your assembler supports .register. */
+#undef HAVE_AS_REGISTER_PSEUDO_OP
+
+/* Define if your assembler and linker support unaligned PC relative relocs.
+   */
+#undef HAVE_AS_SPARC_UA_PCREL
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define if __attribute__((visibility("hidden"))) is supported. */
+#undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define if you have the long double type and it is bigger than a double */
+#undef HAVE_LONG_DOUBLE
+
+/* Define to 1 if you have the `memcpy' function. */
+#define HAVE_MEMCPY 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mmap' function. */
+#define HAVE_MMAP 1
+
+/* Define if mmap with MAP_ANON(YMOUS) works. */
+#define HAVE_MMAP_ANON 1
+
+/* Define if mmap of /dev/zero works. */
+#define HAVE_MMAP_DEV_ZERO 1
+
+/* Define if read-only mmap of a plain file works. */
+#define HAVE_MMAP_FILE 1
+
+/* Define if .eh_frame sections should be read-only. */
+#undef HAVE_RO_EH_FRAME
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#define HAVE_SYS_MMAN_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+#undef NO_MINUS_C_MINUS_O
+
+/* Name of package */
+#define PACKAGE "libffi"
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* The size of `double', as computed by sizeof. */
+#define SIZEOF_DOUBLE 8
+
+/* The size of `long double', as computed by sizeof. */
+#undef SIZEOF_LONG_DOUBLE
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at runtime.
+    STACK_DIRECTION > 0 => grows toward higher addresses
+    STACK_DIRECTION < 0 => grows toward lower addresses
+    STACK_DIRECTION = 0 => direction of growth unknown */
+#undef STACK_DIRECTION
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define this if you are using Purify and want to suppress spurious messages.
+   */
+#undef USING_PURIFY
+
+/* Version number of package */
+#undef VERSION
+
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
+#undef WORDS_BIGENDIAN
+
+
+#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
+#ifdef LIBFFI_ASM
+#define FFI_HIDDEN(name) .hidden name
+#else
+#define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
+#endif
+#else
+#ifdef LIBFFI_ASM
+#define FFI_HIDDEN(name)
+#else
+#define FFI_HIDDEN
+#endif
+#endif
+


--- build.sh (orig/build.sh)
+++ build.sh (build.sh)
@@ -5,6 +5,7 @@
 set -ex
 CWD=$(pwd)
 DEBUG=no
+android_abi="$1"

 RELEASE_VERSION=$(cat LATEST_VERSION)
 echo "Building Python VM For Android Release ${RELEASE_VERSION}"
@@ -78,12 +79,12 @@
 ${CWD}/host/pgen ${CWD}/python-src/Grammar/Grammar \
  ${CWD}/python-src/Include/graminit.h \
  ${CWD}/python-src/Python/graminit.c
-ndk-build
+ndk-build APP_ABI:=$android_abi

 # copy out all the needed files
-mv obj/local/armeabi/python ${OUT}/usr/bin
-mv obj/local/armeabi/lib*.so ${OUT}/usr/lib
-mv obj/local/armeabi/*.so ${OUT}/usr/lib/python2.6/lib-dynload
+mv obj/local/$android_abi/python ${OUT}/usr/bin
+mv obj/local/$android_abi/lib*.so ${OUT}/usr/lib
+mv obj/local/$android_abi/*.so ${OUT}/usr/lib/python2.6/lib-dynload
 popd

 pushd ${CWD}/python-libs
@@ -91,7 +92,7 @@
 popd

 ${CWD}/host/bin/python ${OUT}/usr/lib/python2.6/compileall.py ${OUT}/usr/lib/python2.6
-${CWD}/host/bin/python build.py
+${CWD}/host/bin/python build.py $android_abi

 if [ "$DEBUG" != "yes" ]; then
     rm -rf output*

Read More
Posted in Android, Python, x86 | No comments

Thursday, 24 January 2013

Android: Trying to load native library results in a process terminated by signal (11)

Posted on 07:25 by Unknown

Symptoms

You are trying to load your native C/C++ library in an Android application and when at runtime your app calls the System.loadLibrary() function - for example:

static {
        System.loadLibrary("mynativelib");
}

the application dies without core dumping, and the only message you see in LogCat is something like the following:

01-23 19:58:08.699: D/dalvikvm(4146): Trying to load lib /data/data/com.example.myapp/lib/libmynativelib.so 0x42341a50
01-23 19:58:08.709: I/ActivityManager(340): Process com.example.myapp (pid 4146) has died.
01-23 19:58:08.709: W/ActivityManager(340): Force removing ActivityRecord{211d37d0 com.example.myapp/.MyActivity}: app died, no saved state
01-23 19:58:08.719: D/Zygote(188): Process 4146 terminated by signal (11)

Causes

You native library is probably trying to dynamically load another library it depends upon.

Solution

Use the GCC readelf for your ABI to dump the dynamic section of your native library and find out which libraries it depends upon. For example if you are compiling for the x86 ABI:


$ android-ndk-r8d/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-readelf -d libmynativelib.so | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libgnustl_shared.so]
 0x00000001 (NEEDED)                     Shared library: [libiconv.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libstdc++.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]


In this example you only need to load libgnustl_shared.so and libiconv.so before your libmynativelib.so to resolve the dependencies and make the System.loadLibrary() function call happy (the other standard libraries are already preloaded for you by Android). In your static section you will then include the following lines:


static {
        System.loadLibrary("gnustl_shared");
        System.loadLibrary("iconv");
        System.loadLibrary("mynativelib");
}

This should solve the problem.

Read More
Posted in Android, x86 | No comments

Thursday, 10 January 2013

How to port Mozilla SpiderMonkey 1.7 to Android

Posted on 07:47 by Unknown
Another third-party package I needed to cross-compile for Android was Mozilla's SpiderMonkey 1.7 Javascript engine. I found two issues here:

  1. When configuring SpiderMonkey the makefile tries to build two executables (jscpucfg and jskwgen) and then runs them to generate two  configuration header files (jsautocfg.h and jsautokw.h, respectively). The problem when using the Android NDK cross-compiler is that these two executables can only be run on the Android target (for example an ARM processor), while I'm cross-compiling my build from a Linux Ubuntu 12.04 machine with an x86_64 processor architecture. So you get an error that you cannot execute these files on the host machine.
    I solved this problem by copying the two executables to an Android device (Samsung Galaxy S III) using scp and the SSHDroid application, and generating the two header files there:

    $ jscpucfg > jsautocfg.h
    $ jskwgen > jsautokw.h

    then I copied the two files back to my node on my Ubuntu machine and saved in the source trunk under the config sub-directory. Then I changed the makefile to skip generating these two header files when cross-compiling for Android and get them instead from the config sub-directory.
  2. The SpiderMonkey jsnum.c file generates the following error when cross-compiled for Android:

    js-1.7/jsnum.c: In function 'js_InitRuntimeNumberState':
    js-1.7/jsnum.c:578: error: 'struct lconv' has no member named 'thousands_sep'
    js-1.7/jsnum.c:578: error: 'struct lconv' has no member named 'thousands_sep'
    js-1.7/jsnum.c:580: error: 'struct lconv' has no member named 'decimal_point'
    js-1.7/jsnum.c:580: error: 'struct lconv' has no member named 'decimal_point'
    js-1.7/jsnum.c:582: error: 'struct lconv' has no member named 'grouping'
    js-1.7/jsnum.c:582: error: 'struct lconv' has no member named 'grouping'
    gmake[2]: *** [js-1.7.dir/jsnum.c.o] Error 1

    This is caused by the fact that the lconv structure in locale.h shipped with the Android NDK is stubbed with the following comment:

    #if 1 /* MISSING FROM BIONIC - DEFINED TO MAKE libstdc++-v3 happy */
    struct lconv { };
    struct lconv *localeconv(void);
    #endif /* MISSING */

    To solve this problem I applied the following patch to jsnum.c and I was able to successfully cross-compile SpiderMonkey 1.7 for Android.

    --- a/jsnum.c   2013-01-10 10:37:54.413800695 -0500
    +++ b/jsnum.c   2013-01-10 10:06:49.432752061 -0500
    @@ -573,13 +573,28 @@ js_InitRuntimeNumberState(JSContext *cx)
         u.s.lo = 1;
         number_constants[NC_MIN_VALUE].dval = u.d;
     
    -    locale = localeconv();
    -    rt->thousandsSeparator =
    -        JS_strdup(cx, locale->thousands_sep ? locale->thousands_sep : "'");
    -    rt->decimalSeparator =
    -        JS_strdup(cx, locale->decimal_point ? locale->decimal_point : ".");
    -    rt->numGrouping =
    -        JS_strdup(cx, locale->grouping ? locale->grouping : "\3\0");
    +    /* Copy locale-specific separators into the runtime strings. */
    +    const char *thousandsSeparator, *decimalPoint, *grouping;
    +#ifdef HAVE_LOCALECONV
    +    locale = localeconv();
    +    thousandsSeparator = locale->thousands_sep;
    +    decimalPoint = locale->decimal_point;
    +    grouping = locale->grouping;
    +#else
    +    thousandsSeparator = getenv("LOCALE_THOUSANDS_SEP");
    +    decimalPoint = getenv("LOCALE_DECIMAL_POINT");
    +    grouping = getenv("LOCALE_GROUPING");
    +#endif
    +    if (!thousandsSeparator)
    +        thousandsSeparator = "'";
    +    if (!decimalPoint)
    +        decimalPoint = ".";
    +    if (!grouping)
    +        grouping = "\3\0";
    +
    +    rt->thousandsSeparator = JS_strdup(cx, thousandsSeparator);
    +    rt->decimalSeparator = JS_strdup(cx, decimalPoint);
    +    rt->numGrouping = JS_strdup(cx, grouping);
     
         return rt->thousandsSeparator && rt->decimalSeparator && rt->numGrouping;
     }

    Of course you would define HAVE_LOCALECONV only for regular builds but not for Android cross-compilations, so that you could either pass your own definitions for the locale thousands separator, decimal point or locale grouping via environment variables, or use the above defaults.
Read More
Posted in Android, GNU, Javascript | No comments

Wednesday, 9 January 2013

How to inspect expanded C macros with gcc/gcc+

Posted on 12:04 by Unknown
Sometimes you get compilation errors in gcc/g++ and you'd like to inspect the output from the C compiler pre-processor to figure out why certain macros were expanded in such as way to cause an error.
The solution is simply to remove the -o and -c options from your gcc/g++ command line and replace it with

gcc/g++ -E -dD

this will generate on your terminal only the C pre-processor output that is eventually fed to the C/C++ compiler.

For example you are trying to compile Mozilla SpiderMonkey 1.7 and one of  the compiler lines is the following:

/usr/bin/gcc  -Djs_1_7_EXPORTS -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -D_IEEE_LIBM -DJS_EDITLINE -DEDITLINE -DHAVE_VA_COPY -DVA_COPY=va_copy -DPIC -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX -DHAVE_STDLIB -DUNIQUE_HISTORY -O3 -DNDEBUG -fPIC -I../js-1.7  -fPIC -o CMakeFiles/js-1.7.dir/jsarena.c.o   -c js-1.7/jsarena.c

To see the expanded C macros run the following command:

 /usr/bin/gcc  -E -dD -Djs_1_7_EXPORTS -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -D_IEEE_LIBM -DJS_EDITLINE -DEDITLINE -DHAVE_VA_COPY -DVA_COPY=va_copy -DPIC -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX -DHAVE_STDLIB -DUNIQUE_HISTORY -O3 -DNDEBUG -fPIC -I../js-1.7  -fPIC  js-1.7/jsarena.c



Read More
Posted in GNU, Linux | No comments

Sunday, 6 January 2013

Upgrading mid-2007 24in iMac with an SSD and a 2.5in HDD in the optical bay

Posted on 18:40 by Unknown
I own a mid-2007 24in iMac with a 2.4 GHz Intel Core 2 Duo processor, 4GB of DDR2 DRAM, running Mac OS Mountain Lion, and for the past few months the computer was getting slower and slower, and when I was running Windows XP in VMWare Fusion, the machine was often swapping, bringing the iMac to a crawl. Finally I decided to upgrade my iMac by installing an SSD. Two years ago I replaced the Western Digital 500 GB hard drive (that failed on me one day by giving me the gray screen of death at boot time), with a 1 TB WD caviar green which I almost filled since then (about 750 GB used).
So I wanted the fast SSD drive but also to maintain the 1 TB of space available. The solution I adopted (found on several posts on the internet) was to replace the existing SATA HDD with an SSD, and replace the optical drive with a PATA to SATA adapter hosting a 2.5in HDD. To avoid the swapping I also replaced one of the 2 GB memory modules with a new OWC 4GB module, bringing the total available memory to 6GB.

Hardware Parts

This is the list of hardware components I ended up buying for this upgrade:

  • Crucial M4 CT064M4SSD2 2.5" 64GB SATA III MLC Internal Solid State Drive (SSD)
  • SilverStone SDP08 2 x 2.5" to 3.5" Bay Converter
  • Western Digital Scorpio Blue WDBABC0010BNC-NRSN 1 TB 2.5' Internal Hard Drive
  • MCE OptiBay Enclosure for SATA Hard Drive for iMac
  • 4.0GB PC-5300 DDR2 667MHz SO-DIMM 200 Pin Memory Upgrade Module

Hardware Installation

Here is the picture of the tools I used to perform the upgrade (grounding wrist band, 6 Pc. mini torx screwdriver set, spudgers, vacuum cups, philips screwdriver.



I followed the instructions to replace the hard drive and the optical bay from the iFixit web site.
The following picture shows the iMac internal components.



The old 1TB caviar green HDD is shown in the following picture. The idea was to replace it with the SSD mounted on the 2.5'' to 3.5'' bay converter.



This picture shows instead the Apple optical drive (superdrive).


I removed the optical drive and replaced it with the 1TB WD Blue HDD mounted on the MCE OptiBay enclosure as shown in the following picture. I also put a piece of foam in the enclosure gap (top of picture) to prevent the HDD from moving.


Then I installed the Crucial M4 SSD inside the SilverStone 2.5" to 3.5" Bay Converter in the bottom position (there is room to install two SSD or two 2.5'' HDD), in order to align the SATA and power connectors with the iMac motherboard.




The following picture shows the newly installed SSD on the top left, and the WD Blue HDD inside the OptiBay enclosure on the bottom right. Notice I attached the thermal sensor for the SSD directly on the metal frame of the bay converter, and used tape to make sure it stays in position.



All the hardware parts described above fitted perfectly in my iMac and I didn't have to do anything special to install them except for adding the piece of foam in the OptiBay enclosure to prevent the HDD from moving around.

Software Configuration

At this point my iMac had two new unformatted disk drives and my original HDD was sitting on my desk. What I had in mind was to install Mac OS on the Crucial M4 SSD, and put the users on the WD Blue HDD. In fact 64 GB are not enough to store the users directories where for example pictures and movies take a lot of disk space. To restore the system I then followed this procedure.
  • I took the original WD caviar green HDD and installed it in a Rosewill external SATA enclosure I had laying around. Then I connected the external SATA enclosure to the iMac via an USB cable.
  • I powered up the iMac holding the option button. This gave me the option to boot into Mountain Lion from the external WD Caviar Green HDD (volume name Macintosh HD).
  • I logged in and opened the Disk Utility application. Selected the Crucial M4 disk, clicked on the Erase tab and formatted the disk by selecting the Mac OS Extended (journaled) format and naming the volume Macintosh SSD.
  • In a similar way I erased the WD Blue HD disk and named the volume Macintosh HD Users. At the end of this procedure, Disk Utility showed the following on the screen:

  • Then I ran Carbon Copy Cloner and copied all directories from the external Macintosh HD except the /Users directory to the Crucial M4 on volume Macintosh SSD (it is simple to do this since Carbon Copy Cloner allows you to select individual directories to copy from the source). I ended up copying about 32 GB to the Macintosh SSD volume, which took about 1 hour. 
  • I ran Carbon Copy Cloner again but this time for source I selected the /Users directory only from the external Macintosh HD, and Macintosh HD Users for destination. To copy 693 GB Carbon Copy Cloner took about 7 hours and 47 minutes.
  • (If you don't want to use Carbon Copy Cloner, you can copy the files directly using the ditto command. For example to clone the /Users directory: 

  • # sudo ditto /Volumes/Macintosh\ HD/Users /Volumes/Macintosh\ HD\ Users/Users/
    )

  • I then opened the Terminal app, logged in as root and created a symbolic link to the new location of the /Users directory:

  • # sudo su -
    # cd /Volumes/Macintosh\ SSD
    # ln -s /Volumes/Macintosh\ HD\ Users/Users/ Users
At this point I rebooted the iMac and when it came back all my original logins with their setting were magically preserved. MacOSX now boots in 13 seconds, and opening applications is almost instantaneous. Now I still had to do some tweaks to make the new setup even better. I followed the suggestion from Martin's blog (Optimizing MacOS X Lion for SSD).
  1. I went to System Preferences, clicked on Users & Groups, clicked the lock icon to unlock the advanced editing. Once unlocked, I right-clicked on each user account and chose Advanced Options from the pop-up menu. Once in the Advanced Options dialog, I changed the Home directory of the user from /Users/user-name to the new location (/Volumes/Macintosh\ HD\ Users/Users/user-name).
  2. I installed and enabled TrimEnabler from this web site.
  3. I set the noatime flag to prevent MacOS from updating the SSD file system every time a file is accessed.
  4. I used the WD Blue HDD for temporary files.

    sudo ditto /private/tmp /Volumes/Macintosh\ HD\ Users/private/tmp
    sudo rm -rf /private/tmpsudo ln -s /Volumes/Macintosh\ HD\ Users//private/tmp /private/tmp
I rebooted the iMac another time and verified that Trim was working, the root file system was mounted with the noatime flag and that temporary files were going to the HDD drive instead of the SSD.
Given new life to an old machine. I'm pretty happy now.
Read More
Posted in Apple, iMac, MacOSX | No comments
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • Configuring the Apple Airport Extreme with Verizon FIOS
    I have Verizon FIOS triple-play service and I love the TV picture quality and internet speed and reliability, but I don't like Verizon...
  • How to Cross-Compile libiconv for Android
    If your legacy C/C++ code includes <iconv.h> to convert the encoding of characters from one coded character set to another, and you ne...
  • Problems with new version of rpmbuild
    The Problem With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the...
  • Meeting The Tate's
       Hello, we are Cody and Aimee Tate. We live in Florida and have been married for 3 years. Recently we have decided to start doing product ...
  • Process Attribution In Network Traffic
    Author: Phil -at- DigitalOperatives Overview Digital Operatives recently completed a DARPA Cyber Fast Track (CFT) contract called  Process A...
  • Transferring Files from a computer to your Android device
    Android devices have file systems similar to regular computers. Subject to permissions restrictions, we can transfer files from a computer t...
  • How to build the gcc Fortran cross-compiler for Android (ARM and x86)
    If you need to cross-compile for Android a program written in Fortran, you know already that the official Android NDK does not come with the...
  • Arduino and 7-segment LED counter driven by two tactile switches
    I have posted on YouTube a couple of videos about a project I made with the Arduino prototype board. The circuit uses an Arduino mini and ...
  • Welcome
    After many years of searching the web for tips and tricks about computers, operating systems and programming languages, it's finally tim...
  • PAINT released to the public for Research Purposes Only
    Digital Operatives is proud to release to the public for Research Purposes Only, a beta version of PAINT, Process Attribution In Network Tra...

Categories

  • amazon
  • amazon.com
  • Android
  • Apple
  • Arduino
  • ARM
  • baby
  • baby reviews
  • back to school
  • beef jerky
  • bicycle. wagon
  • bike
  • Blanket Buddies
  • blogging
  • Blogging with The Tate's
  • books
  • busybox
  • camera
  • camera giveaway
  • candle giveaway
  • candles
  • CaseApp
  • CentOS
  • coffee
  • david haskell
  • dermorganic
  • DHCP
  • digital camera
  • events
  • Florida
  • Fortran
  • free blogger giveaway
  • free blogger sign-ups
  • full of flavor
  • giveaways
  • GNU
  • GPON
  • hair care
  • happy husband
  • Hot tea
  • Husband and Wife perspective
  • iMac
  • ipad
  • iphone
  • iphone case
  • iphone case review
  • Javascript
  • Keurig Coffee Review
  • Keurig Review
  • Kindle
  • ksh
  • LifeProof iPhone Case Review
  • Linux
  • MacOSX
  • Malachite Bloomers
  • man and women perspective
  • meat
  • Mips
  • Network
  • Pretzel Crisps
  • Pretzels
  • product reviews
  • products
  • Python
  • Router
  • scentsy
  • scentsy candles
  • school
  • scooter
  • security system
  • skin care
  • snacks
  • sony
  • sony cyber-shot
  • Stuff Animal
  • suface pro
  • Summer
  • summer fun
  • surface pro giveaway
  • techno thriller
  • Timjan Design
  • too much information
  • UNIX
  • vegan
  • vegan products
  • verizon
  • verizon fios
  • VitaminsBaby
  • waterproof case
  • Windows
  • x86
  • yummy

Blog Archive

  • ▼  2013 (41)
    • ▼  November (2)
      • Too Much Information, by: David Haskell, Book Review
      • VERIZON... What did you change?
    • ►  October (2)
    • ►  September (3)
    • ►  August (3)
    • ►  July (2)
    • ►  June (2)
    • ►  May (6)
    • ►  April (8)
    • ►  March (2)
    • ►  February (5)
    • ►  January (6)
  • ►  2012 (17)
    • ►  December (3)
    • ►  November (4)
    • ►  October (8)
    • ►  July (1)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile