From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6246 invoked by alias); 6 Apr 2010 17:09:02 -0000 Received: (qmail 6226 invoked by uid 22791); 6 Apr 2010 17:08:57 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SARE_MSGID_LONG45,TW_XG,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-iw0-f200.google.com (HELO mail-iw0-f200.google.com) (209.85.223.200) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Apr 2010 17:08:51 +0000 Received: by iwn38 with SMTP id 38so110038iwn.8 for ; Tue, 06 Apr 2010 10:08:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.208.68 with HTTP; Tue, 6 Apr 2010 10:08:29 -0700 (PDT) From: Vaibhav Shrimali Date: Tue, 06 Apr 2010 17:09:00 -0000 Received: by 10.231.146.144 with SMTP id h16mr3489082ibv.18.1270573729165; Tue, 06 Apr 2010 10:08:49 -0700 (PDT) Message-ID: Subject: Need to modify the compiler's frame structure... but experiencing difficulties...need urgent help.. To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg00026.txt.bz2 Hello dignitaries, My name is Vaibhav Shrimali and I am working in the area of system security. For my research I am required to make changes in the compiler to implement the stack frame layout in the following fashion as described below. -------------------------- | ARGUMENTS | -------------------------- <--ARGUMENT POINTER | RETURN ADDRESS | -------------------------- |*~*RET ADDR XOR NEW EBP*~*| -------------------------- | SAVED FRAME POINTER | -------------------------- <--HARD FRAME POINTER (NEW EBP) | SAVED REGISTERS | -------------------------- | PADDING 1 | -------------------------- | VARIABLE ARGUMENT REGS | -------------------------- <--FRAME POINTER | FRAME | -------------------------- | PADDING 2 | -------------------------- Here I want to push a copy of the return address just below the original one and after frame pointer is pushed and a new hard_frame_pointer is calculated, I want to encrypt(XOR) the duplicate return address with the current hard_frame_pointer. While returning, the encrypted return address is decrypted and compared with the original return address. If any discrepancies are found, the program flow is redirected to an overflow monitor, else the function returns normally. Note: This approach is only for those methods where frame pointer is required. Now to implement this approach I have come to know that I will have to make changes in three areas, namely: -- ix86_frame structure -- ix86_compute_frame_layout() -- ix86_expand_prologue() -- ix86_expand_epilogue() I am confused about what changes should I make in the ix86_frame struct and ix86_compute_frame_layout() method. There are few questions whose answers I am seeking and need your help. 1. How and where to account for an extra copy of return address? 2. Should the duplicate return address be accounted manually in 'frame->nregs'. If so, shall I just increment it by one or something else should be done? 3. I think the frame size should not be changed. Am I correct? 4. The offset of hard frame pointer and frame pointer should be affected. Is the offset for hard_frame_pointer calculated correctedly for this approach? /* Skip return address and saved base pointer. */ /* offset = 3 if frame pointer needed else 1 */ offset = frame_pointer_needed ? UNITS_PER_WORD * 3 : UNITS_PER_WORD; frame->hard_frame_pointer_offset = offset; In the ix86_expand_prologue() method I have to push a copy of return address just below it and later XOR(^) it with the current hard_frame_pointer. For this I have modified the following method in this way: x = cfun->machine->force_align_arg_pointer; x = gen_frame_mem (Pmode, plus_constant (x, -4)); insn = emit_insn (gen_push (x)); RTX_FRAME_RELATED_P (insn) = 1; /* Pushing another copy of return address */ insn = emit_insn (gen_push (x)); RTX_FRAME_RELATED_P (insn) = 1; ................... .................... if (frame_pointer_needed) { rtx r,set1; insn = emit_insn (gen_push (hard_frame_pointer_rtx)); RTX_FRAME_RELATED_P (insn) = 1; insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx); RTX_FRAME_RELATED_P (insn) = 1; r = cfun->machine->force_align_arg_pointer; r = gen_frame_mem (Pmode, plus_constant (r, -8)); /*memory containing the duplicate (encrypted) return address */ set1 = gen_rtx_SET (VOIDmode,r,simplify_binary_operation(XOR, VOIDmode, r, hard_frame_pointer_rtx)); RTX_FRAME_RELATED_P (set1) = 1; } I tried to build the compiler after making the above changes, there was no error in the i386.c file that I modified, but the compilation resulted in an error. The config.log file in '/home/vebs/gcc/gcc-4.3.3-build/i686-pc-linux-gnu/libgcc' folder is shown below. It says it has following error: conftest.c: In function 'main': conftest.c:16: internal compiler error: in gen_reg_rtx, at emit-rtl.c:865 Please help me identify where am I wrong. I need urgent help for my research as I am working on a dedline. Please help me out. Thank You. '/home/vebs/gcc/gcc-4.3.3-build/i686-pc-linux-gnu/libgcc/config.log':- ######################################################################################################### This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by GNU C Runtime Library configure 1.0, which was generated by GNU Autoconf 2.59. Invocation command line was $ /home/vebs/gcc/gcc-4.3.3/libgcc/configure --cache-file=./config.cache --enable-multilib --enable-languages=c,c++,fortran,java,objc --program-transform-name=s,y,y, --with-target-subdir=i686-pc-linux-gnu --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --srcdir=/home/vebs/gcc/gcc-4.3.3/libgcc --disable-intermodule --enable-checking=yes,types --disable-coverage --enable-languages=c ## --------- ## ## Platform. ## ## --------- ## hostname = vebs-laptop uname -m = i686 uname -r = 2.6.31-14-generic uname -s = Linux uname -v = #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 /usr/bin/uname -p = unknown /bin/uname -X = unknown /bin/arch = unknown /usr/bin/arch -k = unknown /usr/convex/getsysinfo = unknown hostinfo = unknown /bin/machine = unknown /usr/bin/oslevel = unknown /bin/universe = unknown PATH: /usr/local/sbin PATH: /usr/local/bin PATH: /usr/sbin PATH: /usr/bin PATH: /sbin PATH: /bin PATH: /usr/games ## ----------- ## ## Core tests. ## ## ----------- ## configure:1198: creating cache ./config.cache configure:1373: checking for --enable-version-specific-runtime-libs configure:1388: result: no configure:1420: checking for a BSD-compatible install configure:1475: result: /usr/bin/install -c configure:1491: checking for gawk configure:1520: result: no configure:1491: checking for mawk configure:1507: found /usr/bin/mawk configure:1517: result: mawk configure:1540: checking build system type configure:1558: result: i686-pc-linux-gnu configure:1566: checking host system type configure:1580: result: i686-pc-linux-gnu configure:1639: checking for i686-pc-linux-gnu-ar configure:1665: result: ar configure:1718: checking for i686-pc-linux-gnu-lipo configure:1744: result: lipo configure:1798: checking for i686-pc-linux-gnu-nm configure:1824: result: /home/vebs/gcc/gcc-4.3.3-build/./gcc/nm configure:1877: checking for i686-pc-linux-gnu-ranlib configure:1903: result: ranlib configure:1957: checking for i686-pc-linux-gnu-strip configure:1983: result: strip configure:2034: checking whether ln -s works configure:2038: result: yes configure:2055: checking for i686-pc-linux-gnu-gcc configure:2081: result: /home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include configure:2363: checking for C compiler version configure:2366: /home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include --version &5 xgcc (GCC) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. configure:2369: $? = 0 configure:2371: /home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include -v &5 Reading specs from /home/vebs/gcc/gcc-4.3.3-build/./gcc/specs Target: i686-pc-linux-gnu Configured with: /home/vebs/gcc/gcc-4.3.3/configure Thread model: posix gcc version 4.3.3 (GCC) configure:2374: $? = 0 configure:2376: /home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include -V &5 xgcc: '-V' must come at the start of the command line configure:2379: $? = 1 configure:2398: /home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include -o conftest -g -fkeep-inline-functions conftest.c >&5 conftest.c: In function 'main': conftest.c:16: internal compiler error: in gen_reg_rtx, at emit-rtl.c:865 Please submit a full bug report, with preprocessed source if appropriate. See for instructions. configure:2401: $? = 1 configure:2567: checking for suffix of object files configure:2588: /home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include -c -g -fkeep-inline-functions conftest.c >&5 conftest.c: In function 'main': conftest.c:16: internal compiler error: in gen_reg_rtx, at emit-rtl.c:865 Please submit a full bug report, with preprocessed source if appropriate. See for instructions. configure:2591: $? = 1 configure: failed program was: | /* confdefs.h. */ | | #define PACKAGE_NAME "GNU C Runtime Library" | #define PACKAGE_TARNAME "libgcc" | #define PACKAGE_VERSION "1.0" | #define PACKAGE_STRING "GNU C Runtime Library 1.0" | #define PACKAGE_BUGREPORT "" | /* end confdefs.h. */ | | int | main () | { | | ; | return 0; | } configure:2605: error: cannot compute suffix of object files: cannot compile See `config.log' for more details. ## ---------------- ## ## Cache variables. ## ## ---------------- ## ac_cv_build=i686-pc-linux-gnu ac_cv_build_alias=i686-pc-linux-gnu ac_cv_env_CC_set=set ac_cv_env_CC_value='/home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include' ac_cv_env_CFLAGS_set=set ac_cv_env_CFLAGS_value='-g -fkeep-inline-functions' ac_cv_env_CPPFLAGS_set=set ac_cv_env_CPPFLAGS_value= ac_cv_env_CPP_set= ac_cv_env_CPP_value= ac_cv_env_LDFLAGS_set=set ac_cv_env_LDFLAGS_value= ac_cv_env_build_alias_set=set ac_cv_env_build_alias_value=i686-pc-linux-gnu ac_cv_env_host_alias_set=set ac_cv_env_host_alias_value=i686-pc-linux-gnu ac_cv_env_target_alias_set=set ac_cv_env_target_alias_value=i686-pc-linux-gnu ac_cv_host=i686-pc-linux-gnu ac_cv_host_alias=i686-pc-linux-gnu ac_cv_prog_AR=ar ac_cv_prog_AWK=mawk ac_cv_prog_CC='/home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include' ac_cv_prog_LIPO=lipo ac_cv_prog_NM=/home/vebs/gcc/gcc-4.3.3-build/./gcc/nm ac_cv_prog_RANLIB=ranlib ac_cv_prog_STRIP=strip ## ----------------- ## ## Output variables. ## ## ----------------- ## AR='ar' AWK='mawk' CC='/home/vebs/gcc/gcc-4.3.3-build/./gcc/xgcc -B/home/vebs/gcc/gcc-4.3.3-build/./gcc/ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -isystem /usr/local/i686-pc-linux-gnu/sys-include' CFLAGS='-g -fkeep-inline-functions' CPP='' CPPFLAGS='' DEFS='' ECHO_C='' ECHO_N='-n' ECHO_T='' EXEEXT='' INSTALL_DATA='/usr/bin/install -c -m 644' INSTALL_PROGRAM='/usr/bin/install -c' INSTALL_SCRIPT='/usr/bin/install -c' LDFLAGS='' LIBOBJS='' LIBS='' LIPO='lipo' LN_S='ln -s' LTLIBOBJS='' NM='/home/vebs/gcc/gcc-4.3.3-build/./gcc/nm' OBJEXT='' PACKAGE_BUGREPORT='' PACKAGE_NAME='GNU C Runtime Library' PACKAGE_STRING='GNU C Runtime Library 1.0' PACKAGE_TARNAME='libgcc' PACKAGE_VERSION='1.0' PATH_SEPARATOR=':' RANLIB='ranlib' SHELL='/bin/bash' STRIP='strip' ac_ct_AR='' ac_ct_CC='' ac_ct_LIPO='' ac_ct_NM='' ac_ct_RANLIB='' ac_ct_STRIP='' asm_hidden_op='' bindir='${exec_prefix}/bin' build='i686-pc-linux-gnu' build_alias='i686-pc-linux-gnu' build_cpu='i686' build_libsubdir='build-i686-pc-linux-gnu' build_os='linux-gnu' build_subdir='build-i686-pc-linux-gnu' build_vendor='pc' datadir='${prefix}/share' decimal_float='' enable_decimal_float='' enable_shared='yes' exec_prefix='NONE' extra_parts='' fixed_point='' host='i686-pc-linux-gnu' host_alias='i686-pc-linux-gnu' host_cpu='i686' host_noncanonical='i686-pc-linux-gnu' host_os='linux-gnu' host_subdir='.' host_vendor='pc' includedir='${prefix}/include' infodir='${prefix}/info' libdir='${exec_prefix}/lib' libexecdir='${exec_prefix}/libexec' libgcc_topdir='/home/vebs/gcc/gcc-4.3.3/libgcc/..' localstatedir='${prefix}/var' mandir='${prefix}/man' oldincludedir='/usr/include' prefix='NONE' program_transform_name='s,y,y,' sbindir='${exec_prefix}/sbin' set_have_cc_tls='' sharedstatedir='${prefix}/com' slibdir='$(libdir)' sysconfdir='${prefix}/etc' target_alias='i686-pc-linux-gnu' target_subdir='i686-pc-linux-gnu' tmake_file='' vis_hide='' ## ----------- ## ## confdefs.h. ## ## ----------- ## #define PACKAGE_BUGREPORT "" #define PACKAGE_NAME "GNU C Runtime Library" #define PACKAGE_STRING "GNU C Runtime Library 1.0" #define PACKAGE_TARNAME "libgcc" #define PACKAGE_VERSION "1.0" configure: exit 1 #################################################################################################################### -- Vaibhav Shrimali BTech(ICT), DA-IICT Gandhinagar