I recently ran into an interesting warning on newer versions of ARM GCC, including the latest (as of this writing) Arm GNU Toolchain 12.3.Rel1. In particular I’m dealing with arm-none-linux-gnueabihf-g++. Here’s a very simple example program that demonstrates the warning:

#include <vector>
#include <iostream>

int main(int argc, char *argv[])
{
	std::vector<double> test;
	test.push_back(50.0);

	std::cout << test[0] << std::endl;

	return 0;
}

Here’s my compilation command:

arm-none-linux-gnueabihf-g++ test.c -o test

When I compile this code, I get the following warnings about an ABI change that happened in GCC 7.1:

note: parameter passing for argument of type '__gnu_cxx::__normal_iterator<double*, std::vector<double> >' changed in GCC 7.1
note: parameter passing for argument of type 'std::vector<double>::iterator' changed in GCC 7.1

They both relate to the push_back() call. Basically, GCC is alerting me that if this interacts with any libraries that were compiled with GCC versions before 7.1, I could run into issues. Definitely a good thing for GCC to be letting me know about just in case.

Anyway, I knew that this wouldn’t affect me, so I wanted to acknowledge the warning and not see it again for this line of code. Some quick Googling led me to this excellent Stack Overflow question about it. In summary, GCC provides the following undocumented option to disable the warning:

-Wno-psabi

This seems to disable all processor-specific ABI warnings. But do I really want to disable all of them? What if another ABI change occurs in the future? That seems like a legitimate concern, so rather than disabling all psABI warnings, I’ll just disable the psABI warning on that line:

#include <vector>
#include <iostream>

int main(int argc, char *argv[])
{
	std::vector<double> test;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpsabi"
	test.push_back(50.0);
#pragma GCC diagnostic pop

	std::cout << test[0] << std::endl;

	return 0;
}

That should do the trick, right?

Nope. It doesn’t. The warning still appears, even if I wrap the entire file with the pragmas instead of just the single line. The Stack Overflow answer says to use:

#pragma GCC diagnostic ignored "-Wno-psabi"

…but that’s not correct if you compare it to how you’re supposed to use that same pragma with other warnings. Plus, it adds a new warning that confirms it’s definitely not the correct way to do it:

warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]

If I use the pragma the original way in my sample code above, I don’t get this “unknown option” warning. That means GCC is recognizing that I’m asking for the warning to be disabled, but it effectively doesn’t disable it.

So how do you disable this warning without sacrificing the ability to be notified of future ABI changes? In my situation, the offending line was actually in a header file which really complicated matters. What my coworker and I settled on was moving the function to a .cpp file and only adding the -Wno-psabi compiler option to that particular file’s CXXFLAGS.

That seems like a pretty messy solution though. What if another ABI change in that same file pops up in the future? I could potentially end up silently ignoring it even though it might affect me. The pragma seems like the best way to go for acknowledging only a specific instance of the warning, so it’s a shame that it doesn’t work. Does anyone else know a better way to avoid this? Am I wrong in not wanting to apply -Wno-psabi to the entire project? It appears I’m not alone because both the person who asked the Stack Overflow question as well as the answerer shared my same concern.

Trackback

1 comment

  1. […] Doug Brown ☛ How am I supposed to safely disable this warning on ARM GCC? […]

Add your comment now