Author Topic: Discarding local labels and equ?  (Read 6221 times)

Offline clockworkd

  • Jr. Member
  • *
  • Posts: 10
Discarding local labels and equ?
« on: March 04, 2020, 08:23:48 AM »
Hullo there,
I've just been adding DWARF debugging information to the output of my BASIC compiler (x86-64, Linux). Everything was going well, however I've hit a problem. Local labels (dotted) and constants defined with equ make their way into the final executable. So when I ask the GNU debugger for a backtrace, I get lots of irrelevant information. (For example, each function has a little "helper" function that zeroes the stack, and some equs that record call frame information). The backtrace is thus quite confusing to read.
Is there anyway to make it so these symbols don't end up in the final binary - just the function names themselves?
Thanks.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Discarding local labels and equ?
« Reply #1 on: March 04, 2020, 10:07:22 PM »
I am fairly certain that there is nothing Nasm itself can do for you. Adding the "-s" switch to ld will strip all debugging information, which is  not what you want! It is remotely possible that the "strip" utility can strip some symbols but not others. I kinda doubt it. Think about how any utility would know that you consider certain information "irrelevant". If you left it out, your program wouldn't work as intended... As such, I think it's going to be up to you to skip over the "irrelevant" parts. I could be wrong...

Best,
Frank


Offline clockworkd

  • Jr. Member
  • *
  • Posts: 10
Re: Discarding local labels and equ?
« Reply #2 on: March 05, 2020, 02:36:35 AM »
Thank-you Frank for your quick answer. After I posted this topic I saw on stackoverflow that someone mentioned that the strip  command supports wildcards and so might be able to strip everything containing a dot. I'll have a look into that.
Would the nasm developers accept a patch to add this partial stripping functionality as a command line switch? I think it would make nasm much more useful as a compiler backend and bring it more into line with fasm.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Discarding local labels and equ?
« Reply #3 on: March 05, 2020, 02:54:45 AM »
I am not currently involved in Nasm development. You could ask.

If you replace the "equ"s with "%define"s, this might keep that info out of your executable.

Best,
Frank


Offline clockworkd

  • Jr. Member
  • *
  • Posts: 10
Re: Discarding local labels and equ?
« Reply #4 on: March 05, 2020, 11:02:05 AM »
Hi,
When I tried using %defines nasm made several complaints, something about expressions not being constant, or simple or relocatable.  :-\
Well, I have asked, now!  :)

Offline clockworkd

  • Jr. Member
  • *
  • Posts: 10
Re: Discarding local labels and equ?
« Reply #5 on: March 06, 2020, 03:07:26 AM »
I've written a patch now so will hopefully email it off tomorrow. Who is the best person to email it to?
To clarify, it's not a patch to invoke "strip' or anything heavy-handed  like that, I've just added a command line switch to optionally  stop nasm spewing out all the unwanted labels in the first place.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Discarding local labels and equ?
« Reply #6 on: March 06, 2020, 03:37:12 AM »

Offline clockworkd

  • Jr. Member
  • *
  • Posts: 10
Re: Discarding local labels and equ?
« Reply #7 on: March 07, 2020, 01:43:20 AM »
Hullo again Frank.
Sorry for being dumb - after I read your message I saw that there was a file called SubmittingPatches which had this info.
I've submitted my patch now. It'd be really cool if it was merged because I've never contributed to (someone else's) free software project before.