SKGaur's Blog

January 25, 2010

Compile gcc for Solaris 10 on x86 platform

Filed under: Uncategorized — sumitkgaur @ 10:25 am
Tags:

Buzz sentence for me these days “How to compile gcc on Solaris10 for x86 platform”. There are a lot of problems and missing links exists in the latest source code available for gcc. Use following steps to get gcc compiled successfully on S10 for x86.
1) Download the gcc source code using any tool available to you, for example in my case i used svn to download the aource tree of gcc.
svn checkout http://gcc.gnu.org/svn/gcc/trunk gcc
This will create a gcc directory with all source files init.
2) Download latest binutils from http://ftp.gnu.org/gnu/binutils/ to compile loader and other tools.
3) Optional thing is to create a seprate directory by linking all the source files for running gmake.
4) Now first compile binutil directory using following command
./configure –prefix= –with-gmp= –with-mpfr=

** Here –with-gmp and –with-mpfr paths need to set before running configure command. So if you do not have gmp and mprf library then first download and compile them.
The GNU MP Bignum Library
The MPFR Library

then
./gmake
./gmake install
5) Now go in gcc soource dir
./configure –prefix= –with-gmp-include= –with-gmp-lib= -with-mpfr-include= –with-mpfr-lib= –disable-nls
–disable-multilib –with-gnu-ld –with-gnu-as
./gmake -j 8
./gmake install

now you are done .

BUT it is not that easy … these are some troubles i faced and fixed. Have an look …

1) Following changes are required for lib/gen-classlist.sh

abs_top_builddir=`cd “${top_builddir}”; pwd`
> abs_top_srcdir=`cd “/net/dv1.india/vol/wsvol/ws1/sg160228/OPENAIS/gcc/libjava/classpath”; pwd`
> if test “$abs_top_builddir” != “$abs_top_srcdir”; then

if test -f ${top_builddir}/lib/classes.2; then

2) Following changes are required for classpath/lib/Makefile

< if ! [ -e gnu ]; then mkdir gnu; fi
< if ! [ -e gnu/java ]; then mkdir gnu/java; fi
< if ! [ -e gnu/java/locale ]; then mkdir gnu/java/locale; fi
if test ! -d gnu; then mkdir gnu; fi
> if test ! -d gnu/java; then mkdir gnu/java; fi
> if test ! -d gnu/java/locale; then mkdir gnu/java/locale; fi

> if test ! -d gnu/javax/swing/plaf/gtk/icons; then mkdir -p gnu/javax/swing/plaf/gtk/icons; fi

if test ! -d $$p; then mkdir $$p; fi; \

3) Following changes are required for libjava/scripts/jar

if test -f “$2″/”$1″; then

elif test -f “$1″; then

mkdir_p_fun () {

mkdir_p=’mkdir_p_fun’
+
4) Following changes are required for /gcc/gcc/Makefile

< STRICT2_WARN = -pedantic -Wno-long-long -Wno-variadic-macros \
STRICT2_WARN = -pedantic -Wno-long-long \
> -Wold-style-definition -Wmissing-format-attribute \

< echo 'SYSTEM_HEADER_DIR="'"$(SYSTEM_HEADER_DIR)"'"'
$(DESTDIR)$(itoolsdatadir)/mkheaders.conf

> echo ‘SYSTEM_HEADER_DIR=”$(SYSTEM_HEADER_DIR)”‘ > $(DESTDIR)$(itoolsdatadir)/mkheaders.conf

5) There could the case when gcc loader could not load some directories then we need to copy that particular .so file in $BuildDir/$BuildDir/lib/ . For this i think there is some bug with binutils loader that is why it could not load same library from /usr/bin or /lib/. So need to go for above work around.

6) Set following environmental param if required :
LD_LIBRARY_PATH , LD_RUN_PATH , CC , RPATH.

Dirrefent ways to run system command in C++ programme

Filed under: Uncategorized — sumitkgaur @ 10:24 am
Tags:

Before proceding a short intro of forking

(o) fork()
The fork() system call will spawn a new child process which is an identical process to the parent except that has a new system process ID. The process is copied in memory from the parent and a new process structure is assigned by the kernel. The return value of the function is which discriminates the two threads of execution. A zero is returned by the fork function in the child’s process.

The environment, resource limits, umask, controlling terminal, current working directory, root directory, signal masks and other process resources are also duplicated from the parent in the forked child process.
** Problems
1) Some memory duplicated by a forked process such as file pointers, will cause intermixed output from both processes.
2) Race conditions can be created due to the unpredictability of when the kernel scheduler runs portions or time slices of the process.

(o) vfork()
Some systems have a system call vfork(), which was originally designed as a lower-overhead version of fork().The basic difference between the two is that when a new process is created with vfork(), the parent process is temporarily suspended, and the child process might borrow the parent’s address space. This strange state of affairs continues until the child process either exits, or calls execve(), at which point the parent process continues.
** Problems
1) A deadlock condition may occur if the child process does not terminate, the parent process will not proceed.

(o) int system ( const char * command )
Invokes the command processor to execute a command. Once the command execution has terminated, the processor gives the control back to the program, returning an int value, whose interpretation is system-dependent. C string containing the system command to be executed.
This function is implemented using fork(), exec() and waitpid(). The command string is executed by calling /bin/sh -c command-string. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored. The call “blocks” and waits for the task to be performed before continuing.
** Problems
1) Rrequired memory to fork, so in case of no memory this would not work.

(o) popen()
The popen() call opens a process by creating a pipe, forking, and invoking the shell (bourne shell on Linux). The advantage to using popen() is that it will allow one to interrogate the results of the command issued.

** Problems
1) Rrequired memory to fork, so in case of no memory this would not work.

(o) exec() and execve()
The exec() family of functions will initiate a program from within a program. They are also various front-end functions to execve().The functions return an integer error code. (0=Ok/-1=Fail).

more detailed info

http://www.cse.msu.edu/cgi-bin/man2html?exec?2?/usr/man

** Problems
1) Rrequired memory to fork, so in case of no memory this would not work.

(o) By using kernel interface
A central theme in operating system design is the kernel interface. The kernel interface is the API of the operating system, and therefore the choice of API determines the structure, features and limitations of an operating system. We can use such interfaces to run some of commands we need in emergency.

e.g To run reboot command include and use int reboot(int howto);

five points for gdb over dbx knowledge

Filed under: Uncategorized — sumitkgaur @ 10:24 am

I used to work with dbx for debugging any code realated bug but last project I had worked with gdb as project was for linux platform. Here are five points for gdb, need to consider too for dbx users

1) To check any hex dump for a void * type of variable use following command in gdb
(gdb) x/256xb buffer
where 256 is the size of buffer that you could change as per your requirement.

2) gdb supports all the short cuts that we used to do in bash shell like command search for ctrl+r.

3) T check what is in the processor registers
info registers

4) I see the assembly code my program is running use disassemble commad e.g.
disassemble main

5) For adding source path we are using directory command that was pathmap in dbx.

packaging in linux platform

Filed under: Uncategorized — sumitkgaur @ 10:23 am

I have never did packaging in linux platform and had faced a lot of problem in creating a simple spec file. Now as I have through with it I want to share this information in my Blog.
The major portion in linux packaging process is to create a right spec file. Here I am giving a sample and simplest spec file. Assumptions here are we want software get install in /opt/package- name/lib and /opt/package- name/bin directory. Given below is the containt of “Package name”.spec file :-

Summary: Write name of project
Name: Package name
Version: 0.0.1
Release: 1
License: GPL
Group: wite any group name (for detail could go any link given below)
Source: /usr/src/packages/SOURCES/-.tar.gz
BuildRoot: /usr/src/packages/RPMS/x86_64/opt

%description
Project description that will come as information after installation of package.

%prep
%setup -q

%install
mkdir -p $RPM_BUILD_ROOT/opt/write you package name/bin/
mkdir -p $RPM_BUILD_ROOT/opt/write your package name /lib/

install -s -m 0755 /usr/src/packages/BUILD/-/opt/write you package name/bin/* $RPM_BUILD_ROOT/opt/write you package name/bin/
install -s -m 0755 /usr/src/packages/BUILD/-/opt/write you package name/lib/*.so* $RPM_BUILD_ROOT/opt/write you package name/lib/

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(1777,root,root)

/opt/write you package name/bin/*
/opt/write you package name/lib/*.so*

———–
Done
Now simply you need to run following commands

1) Create a rpm file in default folder of /usr/src/packages/RPMS
rpmbuild -ba /usr/src/packages/SPECS/package_name.spec
2) Install rpmfile to the location provided by you in spec file
rpm -ivh /usr/src/packages/RPMS/******.rpm
3) Remove software from the platform
rpm -e magnum-lda
4) Query the package and get detail that you have specified in spec file.
rpm -qpl magnum-lda-1.0.0-1.x86_64.rpm

Steps to burn a CD/DVD in Solaris

Filed under: Uncategorized — sumitkgaur @ 10:23 am
Tags:

1. Create a temporary directory.
2. Copy the files you want to burn to CD/DVD to this temporary directory.
3. Make an iso image out of it.
4. Mount the iso image (to make sure that it works)
5. Now insert the CD/DVD media in the drive and burn the data onto it.

Example:
1. bash#> mkdir ./temp_dir
2. bash#> cp /my_dir_path/myfiles ./temp_dir
3. bash#> mkisofs -J -R -o /my_dir_path/my_files.iso ./temp_dir
4. bash#> lofiadm -a /my_dir_path/my_files.iso
/dev/lofi/1
bash#> mount -F hsfs /dev/lofi/1 /mnt
5. bash#> cd /usb
bash#> cdrw -i /my_dir_path/my_files.iso
Looking for CD devices…
Initializing device…done.
Preparing to write DVD
Writing track 1…done.
Finalizing (Can take several minutes)…done.

make a choice pthread_join or pthread_detach

Filed under: Uncategorized — sumitkgaur @ 10:22 am
Tags:

Depends if you want to get some sort of status code or return value from the thread. If the thread doesn’t need to signal any errors (or it signals errors in some other way than the return code), then using detach is preferable since it (slightly) reduces overhead. If you want to get the return code from the thread, then you need to use pthread_join. pthread_join is also useful for making sure than another thread has finished it’s work.

memory leaks

Filed under: Uncategorized — sumitkgaur @ 10:21 am
Tags:

memory leaks

After debugging a lot i find out the problems with mdb and way easy dbx mem leak cheks. I am writing here steps to find out leaks in mdb Vs dbx . Also current mdb has bug that you have to set sysbp _exit before starting and that gives you pain if you have big appliation to debug(specially threded one).

for mdb :-
[root@o4test45 ]$export LD_PRELOAD=libumem.so.1
[root@o4test45 ]$export UMEM_LOGGING=transaction
[root@o4test45 ]$export UMEM_DEBUG=default

mdb /path/application
> ::sysbp _exit
> run
mdb: failed to dereference symbol: unknown symbol name
> ::run
=======>>> FDP starting [version: 0.0.3 (2008Mar31 08:37)]
mdb: fork1 detected: follow (p)arent or (c)hild? c
mdb: target forked child process 16732 (debugger following child)

mdb: stop on SIGABRT
mdb: target stopped at:
libc.so.1`_lwp_kill+7: jae +0xe
mdb: You’ve got symbols!
Loading modules: [ ld.so.1 libumem.so.1 libc.so.1 ]
>
> ::load libumem
> ::findleaks
BYTES LEAKED VMEM_SEG CALLER
4096 1 bfd58000 MMAP
————————————————————————
Total 1 oversized leak, 4096 bytes

CACHE LEAKED BUFCTL CALLER
———————————————————————-
Total 0 buffers, 0 bytes
>

For DBX :-

export LD_AUDIT=/opt/SUNWspro/lib/rtcaudit.so before starting the process

root@o4test45 ]$export LD_AUDIT=rtcaudit.so
[root@o4test45 ]$export LD_LIBRARY_PATH=/opt/SUNWspro/lib/
[root@o4test45 ]$export LD_LIBRARY_PATH_64=/opt/SUNWspro/lib/amd64/
[root@o4test45 ]$./bin/dbx
For information about new features see `help changes’
To remove this message, put `dbxenv suppress_startup_message 7.6′ in your .dbxrc
(dbx) dbxenv mt_sync_tracking off
(dbx) attach 12279
…. …. …
… …. ….

(dbx) dbxenv rtc_auto_continue on
(dbx) dbxenv rtc_error_log_file_name /tmp/dbx.errlog.101
(dbx) dbxenv rtc_error_stack on
(dbx) check -all
access checking – ON
memuse checking – ON
RTC: Enabling Error Checking…
RTC: Running program…
(dbx) cont
(dbx) showleaks -m 8 -v

Is it not tooo easy then mdb ?

Hello world!

Filed under: Uncategorized — sumitkgaur @ 10:02 am

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.