Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does creating a replacement memset trigger duplicate symbol errors in specific circumstances?
    primarykey
    data
    text
    <p>I recently wrote a few replacements for string routines (memcpy, memset, and memmove). It is my understanding that if the library containing these routines is specified on the compile / link line, these will take precedence over system standard library routines of the same name. If I'm wrong already, please let me know!</p> <p>This works correctly in all testing I did (verified by disassembly that the correct routines are there and glibc routines don't exist), but further testing discovered an odd break caused by this:</p> <p>1) build another file in the same library with -g (I had been building -O2)</p> <p>2) this file has an explicit call to memset</p> <p>3a) if the compile time options work in such a way that this memset is inlined by gcc, everything is OK</p> <p>3b) if, however, the options disable the inlining of a memset call <em>which would have been inlined otherwise</em>, the library will build but using the library to statically link an application causes a duplicate symbol linker error - the other instance of the symbol is the system library's memset.</p> <p>Basically I can build two versions of my library (100's of source files), and by changing the make CFLAGS in one directory from -O1 -g to just -g I can trigger the linker error when this library is used.</p> <p>I can take the working version, run it through nm, and see that it has many undefined references to memset including in routines which are linked into my test case - so I know it should be trying to resolve memset in the working case. When I diff this against the nm output for the broken library, all I see is a few extra undefined memcpy and memset references. If memset resolved in the first case (to my routine), it should in the second.</p> <p>I have also looked at the verbose compiler output and verified that the link lines are exactly the same in both cases, except for the path to this one library.</p> <p>There are two super puzzling things here (among a myriad of other issues):</p> <p>1) Why would a file in a library built -O1 -g link any differently than -g</p> <p>2) Why would a replacement memset, in a user library, conflict with the system memset</p> <p>And for the grand prize, how does 1) cause 2)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload