I’m currently a total beginner with assembly and am learning how to use assembly inline with C for a class. That being said, I’m having a hard time with this particular error when I’m compiling my file:
/tmp/cckHnU89.s: Assembler messages: /tmp/cckHnU89.s:550: Error: symbol `.L16' is already defined /tmp/cckHnU89.s:571: Error: symbol `.L18' is already defined /tmp/cckHnU89.s:576: Error: symbol `.L17' is already defined
I tried replacing the names of the labels with other names since I noticed from the .s file that the labels .L16, .L17, and .L18 are used in my main method as well as in one of my functions. However, when did that I just ended up with a segmentation fault from running the program. Is there a way to change the names of the labels or something else to fix which apparently seems to be a naming conflict?
As far as my CPU, I’m running an Intel Pentium T4500 processor and I’m compiling with gcc version 4.4.3. My code is 300+ lines for the inline assembly portion so I’ll spare whoever reads this. Essentially, I’m just looking for a general answer on how one would normally fix the naming conflict that produces the error above. Anything insight would be greatly appreciated.
My hunch here is (and I just verified it with
g++ -Sandgcc -S) that your own labels are exactly mimicking the naming scheme (.L<num>) for labels automatically assigned to assembler code in GCC.Do the following:
… and then
cat(orless) the resulting.sfile (same base name,.ssuffix, e.g.source.s). You will find numerous labels of that scheme (.L<num>). Now, if you yourself create inline assembly containing the same names as already automatically created labels (from your C code), that would obviously lead to clashes.So the gist: don’t use
.L<num>as your naming scheme for labels, because it will clash.Generally names starting with
.Lseem to ask for trouble here.Example (
test.cpp), compile withg++ -S test.cpp:Compiled on x64 (contents of
test.s):Observe the names starting with
.Lin the resulting assembler file.