What does the "-reloc-mode" compiler flag do?

The doc has these:

-reloc-mode:<string>
		Specifies the reloc mode.
		Available options:
			-reloc-mode:default
			-reloc-mode:static
			-reloc-mode:pic
			-reloc-mode:dynamic-no-pic

is “pic” is similar with “-fpic” for gcc?

1 Like

It states the relocation model for the generated code.

PIC = Position Independent Code

Yes it is similar to -fpic in GCC.

3 Likes

Then whats the difference between “pic” and “dynamic-no-pic” and which should i use when?

1 Like

Even I couldn’t understand this, despite some searches. PIC as I understand is position-independent code, but what is it independent to? When would you want it to be independent? Why would you prefer it being dependent on something else? Does it affect performance? Does it affect debugger?

As i understand, pic is good for shared libraries as the loader can move the code around in memory, and in the code, when you reference something, you can reference it absolutely or relatively, i guess. so pic makes it easier for the shared library. I may be wrong, btw.

For what it’s worth, with a modern OS, everything benefits from being compiled as PIC code because it allows the OS to apply Address Space Layout Randomization (ASLR), which is a form of hardening.

2 Likes