Thread: C guru help needed URGENT

  1. #31
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Salem ,
    would u mind compiling the test code and see you can get it to use the new gettime ?

    thanx again

  2. #32
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you're getting "no symbols", then I think the LD_PRELOAD is a non-starter.

    Code:
    $ gcc foo.c
    $ ls -l ./a.out 
    -rwxrwxr-x 1 sc sc 8435 2012-09-19 11:33 ./a.out
    $ gcc -static foo.c
    $ ls -l ./a.out 
    -rwxrwxr-x 1 sc sc 825738 2012-09-19 11:33 ./a.out
    $ strip a.out 
    $ ls -l ./a.out 
    -rwxrwxr-x 1 sc sc 747096 2012-09-19 11:33 ./a.out
    $ nm a.out 
    nm: a.out: no symbols
    Statically linked executables have the entire library built into them - which is why the default dynamically linked versions are so much smaller (case 1).

    A statically linked executable which has been 'stripped' of symbols (case 3) will have no symbols.

    Which leads me to ask "how do you know it's gettimeofday" that is the issue here?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #33
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Two things
    a)
    This is in strace of the program so i know its using gettime

    Code:
    write(1, "\r\n", 2)                     = 2
    poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 0) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348050630, 92763}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 0) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348050630, 93232}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 0) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348050630, 93700}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 0) = 0 (Timeout)


    b) i ran ld for the test program , it looks like it compiles etc fine but
    ld shows not using the new library i created with new gettime

    machine:~$ ldd main
    linux-gate.so.1 => (0xb7788000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75f2000)
    /lib/ld-linux.so.2 (0xb7789000)




    ProTip: how to break your linux box
    add untested lib.so to /etc/lib.sl.preload
    everything stops working , had fun
    but learnt somthing
    its saying something about undefined __wrap_gettimeofday




    EDIT:
    machine:~$ ld libltimer.so
    ld: warning: cannot find entry symbol _start; not setting start address
    libltimer.so: undefined reference to `__real_gettimeofday'
    Last edited by NetworkLearning; 09-19-2012 at 05:07 AM.

  4. #34
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    guys we almost have it ..please help
    now i removed salems file,
    have an empty gettime returning 0 after sleeping usleep(30000);
    its going to sleep so i know its this getting getting called
    so salem , looks like the wrap thing doesnt work
    can you suggest something else
    Last edited by NetworkLearning; 09-19-2012 at 06:07 AM.

  5. #35
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Ok guys i cannot get clock_gettime even with gcc option -lrt
    is there anything i can do before giving up

  6. #36
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Actually i get
    > nm: i86-image: no symbols
    And if you also do
    ldd i86-image
    do you also get "not a dynamic executable"

    If you do, then none of this LD_PRELOAD or wrapping is going to work.
    The executable is a closed box containing it's own pre-compiled copy of gettimeofday(), and everything else.

    I found this
    c - How to 'link' object file to executable/compiled binary? - Stack Overflow
    The Dyninst looks like a possible way forward, if somewhat over-engineered for a single-shot patch.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #37
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    thanx i think i will just give up
    but it seems so trivial to do that i feel dissapointed in myself

    i KNOW 2 things tho
    1. yes it can use LD_PRELOAD ( as i have been able to use it since 2 days when i started testing )
    2. i cannot even get a small test program , which does nothing to use LD_PRELOAD now
    i think i changed something as now i get this


    machine:~$ LD_PRELOAD=/home/myhome/libf1.o ldd FCaller
    ERROR: ld.so: object '/home/myhome/libf1.o' from LD_PRELOAD cannot be preloaded: ignored.
    ERROR: ld.so: object '/home/myhome/libf1.o' from LD_PRELOAD cannot be preloaded: ignored.
    ERROR: ld.so: object '/home/myhome/libf1.o' from LD_PRELOAD cannot be preloaded: ignored.
    linux-gate.so.1 => (0xb7735000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7579000)
    /lib/ld-linux.so.2 (0xb7736000)

  8. #38
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Salem,
    are you still here

    OK i have my original program reading my gettimeofday ()
    phew
    it preloads the .so file
    and strace shows it using it

    now onto the ACTUAL work
    this program kills my machine

  9. #39
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    [QUOTE=NetworkLearning;1123684]Salem,
    are you still here
    OK i have the program reading my version ( or your version ) of gettimeday but does not seem to be doing anything tho ?

    maybe throttle it more ?

  10. #40
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I've been looking at post #33 again.

    From the gettimeofday() results, it seems to be looping at around 500uS, which means this bit of code is effectively looping at around 2000 times a second.

    I'm curious as to what the code does when it gets a poll timeout (which seems to be what it does most of the time).

    Calling poll() with a zero timeout suggests that it is monitoring something else, and doesn't want to block on a file descriptor. Which is fair enough, IF there is something else to do.
    But there are no other system calls (apart from repeatedly calling gettimeofday), so what is it up to?

    > OK i have the program reading my version ( or your version ) of gettimeday but does not seem to be doing anything tho ?
    Good job.

    But perhaps you could try patching poll as well (or instead), with something like
    Code:
    int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout) {
        if ( timeout == 0 ) timeout = 5;
        return __real_poll(fds,nfds,timeout);
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #41
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Dammit spoke too soon
    Core dumped
    well it ran for a whole 10 mins longer than before thats a good sign
    Last edited by NetworkLearning; 09-20-2012 at 04:21 AM.

  12. #42
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    strace is writing about 15mb a second with this
    is that normal

  13. #43
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    I am testing it now
    but in the meantime if this does not work
    this is what i was thinking

    have a counter written to a file first time gettimeofday is called
    let it get the right time 20 times( as the program does not fully load before calling gettime a few times )
    then after that every call to gettime should return same value .. time standing still

    is it possible ?

    i think it starts a timer when it first calls gettime

  14. #44
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    nope dumped core

  15. #45
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    I have it running the new poll and its dumping core and strace is being written faster

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent help needed
    By bathulasubbu in forum C Programming
    Replies: 3
    Last Post: 03-25-2011, 09:33 AM
  2. Urgent, help needed.
    By sinnclaus in forum C Programming
    Replies: 4
    Last Post: 03-29-2010, 06:08 AM
  3. Urgent! Help Needed
    By DarkManiac in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2004, 07:16 PM
  4. Urgent: Help needed.
    By Cn00b in forum C Programming
    Replies: 12
    Last Post: 04-02-2003, 10:18 PM
  5. Urgent help needed!!!
    By gibs21 in forum C Programming
    Replies: 2
    Last Post: 09-26-2002, 01:45 PM