glibc

glibc function to retrieve current executable name?

烂漫一生 提交于 2019-11-30 05:03:45
i'm wondering if there is a glibc function that i can use from gcc/g++ that will retrieve the current executable. The purpose of this is to provide the -e argument to addr2line as shown in this answer In standard C and glibc, you have argv[0]: int main (int argc, char *argv[]) the first element of the argv array is the program name. However it's not necessarily enough on its own to determine where exactly the executable is. The argument is actually set by the program that ran your program - be it a shell or a window manager - and they aren't terribly helpful. If your program is in the path and

Where is the implementation of strlen() in GCC?

拜拜、爱过 提交于 2019-11-30 04:50:37
Can anyone point me to the definition of strlen() in GCC? I've been grepping release 4.4.2 for about a half hour now (while Googling like crazy) and I can't seem to find where strlen() is actually implemented. You should be looking in glibc, not GCC -- it seems to be defined in strlen.c -- here's a link to strlen.c for glibc version 2.7 ... And here is a link to the glibc SVN repository online for strlen.c . The reason you should be looking at glibc and not gcc is: The GNU C library is used as the C library in the GNU system and most systems with the Linux kernel. I realize this question is

Why is _init from glibc's csu/init-first.c called before _start even if _start is the ELF entry point?

让人想犯罪 __ 提交于 2019-11-30 04:09:01
问题 I first noticed it while playing with GDB's rbreak . , and then made a minimal example: (gdb) file hello_world.out Reading symbols from hello_world.out...done. (gdb) b _init Breakpoint 1 at 0x4003e0 (gdb) b _start Breakpoint 2 at 0x400440 (gdb) run Starting program: /home/ciro/bak/git/cpp/cheat/gdb/hello_world.out Breakpoint 1, _init (argc=1, argv=0x7fffffffd698, envp=0x7fffffffd6a8) at ../csu/init-first.c:52 52 ../csu/init-first.c: No such file or directory. (gdb) continue Continuing.

RHEL 6 - how to install 'GLIBC_2.14' or 'GLIBC_2.15'?

懵懂的女人 提交于 2019-11-30 03:55:01
I need these 2 packages installed on RHEL 6 linux system. They are required by several other programs. When I do: sudo yum install glibc-devel this is output: Loaded plugins: product-id, security Setting up Install Process Package glibc-devel-2.12-1.166.el6_7.1.x86_64 already installed and latest version Nothing to do Is there some EPEL with GLIBC_2.15 for RHEL? If not - what is a workaround here? Yu Tao This often occurs when you build software in RHEL 7 and try to run on RHEL 6. To update GLIBC to any version, simply download the package from https://ftp.gnu.org/gnu/libc/ For example glibc-2

How to turn off Glibc run-time protections?

拈花ヽ惹草 提交于 2019-11-30 03:48:22
I am trying to learn about code vulnerabilities, and am testing some simple programs I wrote. However, many of the issues Glibc catches during runtime (e.g. Stack-Smashing, Double Free, etc.). Thus I would like to be able to run my programs without Glibc's runtime detection errors. Is there a way to turn off Glibc's detection? (like with a compiler flag, etc). I saw in a previous link it is described how to turn off ASLR and Canaries, but this is not what I'd like to do, since it still stops errors like a Double Free and some other heap errors I want to try out (http://stackoverflow.com

libc source location - for download or online viewing?

∥☆過路亽.° 提交于 2019-11-30 00:22:09
Sorry I know this is stupid but where is linux libc source code available? What I downloaded from GNU didn't seem to be what I wanted, specifically I could find nothing in the pthreads function family. Is there an online (hypertexted cross-referenced) version somewhere? osgx Most linuxes use a libc version named glibc . The LXR (online cross-reference system) for glibc is e.g. here http://koala.cs.pub.ro/lxr/glibc/ for 2.9 version (link is broken). I must say that something may be not lxr'ed because some sources are generated in the build process, for example - as i can remember - wrappers

Pthread mutex assertion error

送分小仙女□ 提交于 2019-11-29 23:43:01
I'm encountering the following error at unpredictable times in a linux-based (arm) communications application: pthread_mutex_lock.c:82: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed. Google turns up a lot of references to that error, but little information that seems relevant to my situation. I was wondering if anyone can give me some ideas about how to troubleshoot this error. Does anyone know of a common cause for this assertion? Thanks in advance. Rock solid for 4 days straight. I'm declaring victory on this one. The answer is "stupid user error" (see comments above).

open O_CREAT | O_EXCL on NFS in Linux?

懵懂的女人 提交于 2019-11-29 19:16:42
问题 When in the Linux 2.6 kernel and in NFSv3 did open("fname", O_CREAT|O_EXCL) became valid? The current canonical open(2) system call documentation (http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html) says everything is fine: - O_EXCL - ... On NFS, O_EXCL is only supported when using NFSv3 or later on kernel 2.6 or later. In NFS environments where O_EXCL support is not provided, programs that rely on it for performing locking tasks will contain a race condition. Portable programs

Why does glibc's strlen need to be so complicated to run quickly?

a 夏天 提交于 2019-11-29 18:36:09
I was looking through the strlen code here and I was wondering if the optimizations used in the code are really needed? For example, why wouldn't something like the following work equally good or better? unsigned long strlen(char s[]) { unsigned long i; for (i = 0; s[i] != '\0'; i++) continue; return i; } Isn't simpler code better and/or easier for the compiler to optimize? The code of strlen on the page behind the link looks like this: /* Copyright (C) 1991, 1993, 1997, 2000, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Torbjorn Granlund (tege@sics.se

Delete and invalid pointer

最后都变了- 提交于 2019-11-29 18:27:00
int main() { char* a=new char[20]; cin>>a; cout<<" character at 7-th position."<<a[6]; delete a+4; cout<<a[0]; return 0; } Input: 1234567894567 Output: character at 7-th position.6 *** glibc detected *** ./test free() invalid pointer:.... Now I have 3 questions Is it correct that delete a+4 will only delete the character at a+4 ? If answer to previous one is yes then what happens to a[0] .We should get the output. to delete a chunk of memory we should write delete[] .But in this case how come all the elements are deleted? There are only three types of pointer values you can pass as the operand