LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 05-15-2012, 04:44 AM   #1
smilebhuff
LQ Newbie
 
Registered: May 2012
Posts: 11

Rep: Reputation: Disabled
SIGSEGV segmentation fault at strftime_l lib64/libc.so.6


I'am porting pro*c codes from UNIX to LINUX. The codes are compiled and created executables successfully. But during run time its raising segmentation fault. I debugged the code step by step and the below is the output of GDB debug.

Breakpoint 4 at 0x3b19690f50 (gdb) n 525 strftime (buf, MAX_STRING_LEN, "%d/%b/%Y:%H:%M:%S", dummy_time); (gdb) n

Breakpoint 4, 0x0000003b19690f50 in strftime () from /lib64/libc.so.6 (gdb) n Single stepping until exit from function strftime, which has no line number information. 0x0000003b19690f70 in strftime_l () from /lib64/libc.so.6 (gdb) n Single stepping until exit from function strftime_l, which has no line number information.

Program received signal SIGSEGV, Segmentation fault. 0x0000003b19690f8b in strftime_l () from /lib64/libc.so.6

Actually in code the function strftime() is called not strftime_l(). But I have no idea why it is reaching strftime_l in /lib64/libc.so.6.

This issue is not coming in UNIX. please help on this.
 
Old 05-15-2012, 05:21 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
I think it is pretty obvious, see man strftime. strftime has an implicite default locale, otherwise both do the same thing (so strftime calls strftime_l with an additional argument)
The segfault can be caused by either the buffer is too small or by an illegal variable handling (so for example dummy_time points to nowhere)
 
Old 05-15-2012, 06:13 AM   #3
smilebhuff
LQ Newbie
 
Registered: May 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
thanks for you reply. From my application code strftime() is called. But the segmentation fault is at strftime_l() .

Program received signal SIGSEGV, Segmentation fault. 0x0000003b19690f8b in strftime_l () from /lib64/libc.so.6

My first question is why its going to strftime_l() when am calling strftime() in code.
 
Old 05-15-2012, 06:18 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
because strftime does nothing else just calls strftime_l passing all the original arguments and an additional one: the locale settings. The functionality is implemented in the function strftime_l.
 
Old 05-15-2012, 06:22 AM   #5
smilebhuff
LQ Newbie
 
Registered: May 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
could please help me where to see the definition or implementation of strftime() ? I tried to check whether it calls strftime_l() but I couldn't get where this function implementation is seen?
 
Old 05-15-2012, 06:46 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
(this is obvious). It is usual in the linux world: you can have a few similar functions with almost the same functionality. some of them has default values or assumes some settings. In such cases all those functions invoke the most general one passing their inputs and adding the assumed ones. The functionality is implemented only once and in this general version.

Since this is part of libc you need to download the source code of it and look into the code for the real implementation (there will be a strftime.c or similar). you can find it for example here: http://www.gnu.org/software/libc/download.html
 
1 members found this post helpful.
Old 05-15-2012, 08:35 AM   #7
smilebhuff
LQ Newbie
 
Registered: May 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
you are saying that strftime() calls strftime_l(). Is that on assumption or?
 
Old 05-15-2012, 08:44 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
that is coming from your post. You told you wrote strftime, but you see strftime_l, and asked why. Either you called directly strftime_l or it is called from strftime. The "Single stepping until exit from function strftime" just walked into strftime_l and the code is died inside strftime_l.
 
Old 05-15-2012, 09:24 AM   #9
smilebhuff
LQ Newbie
 
Registered: May 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
ok pan.. thanks for your instant replies.. modified code .. and it woked now!!
 
  


Reply

Tags
linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vsnprintf crashes (Segmentation fault) from /lib64/tls/libc.so.6 Ron_09 Linux - Enterprise 0 09-15-2010 02:34 AM
ImageMagick : SIGSEGV, Segmentation fault pramod.srk Linux - Newbie 7 06-18-2009 07:20 AM
Program received signal SIGSEGV, Segmentation fault go939 Programming 4 08-22-2007 06:54 PM
Program received signal SIGSEGV, Segmentation fault dayalan_cse Linux - Newbie 8 12-15-2006 12:05 AM
SIGSEGV- segmentation fault during execution ashwinipahuja Programming 5 05-02-2004 10:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration