7.150 --share_inlineable_strings, --no_share_inlineable_strings

Controls whether multiple instances of the same inlined string literal use the same object.

With the --share_inlineable_strings option, all instances of an inlined string literal use the same object. Specifically:
  • String literals in the same translation unit are the same object in that translation unit.
  • String literals in externally-visible inline functions are the same object in all translation units.
This can also cause different string literals with the same value to be the same object.
The --no_share_inlineable_strings option suppresses this behavior. That is, the compiler only shares string literals if it provides a performance or code size benefit. For example, consider a string literal that is out of range of an ADR instruction. In this case, the address must be loaded from a literal pool, which costs 4 bytes and is slower than an ADR instruction. As a result, with –Otime the compiler would not share any strings that were out of range, and with –Ospace the compiler would not share any strings smaller than 4 bytes.

Note

The --share_inlineable_strings and --no_share_inlineable_strings options affect string literals in:
  • C or C++ functions not declared inline, but which the compiler has chosen to inline.
  • C inline functions.
The behavior of strings in C++ inline functions is separate from these options, and is defined by the C++ ABI.

Example

Consider the following example code:
#include <stdio.h>

extern inline char *getString(void) { return "abc"; }

int main(int argc, char **argv)
{
  char *a = getString();
  char *(*ptr)() = getString;
  char *b = ptr();


  int a_addr=(int)a;
  int b_addr=(int)b;


  printf("String \"%s\" from getString() called directly is an object at address:          %d\n", a, a_addr);
  printf("String \"%s\" from getString() called using a pointer is an object at address:   %d\n", b, b_addr);

  if (a_addr == b_addr) {
    printf("Objects are the same.\n");
  } else {
    printf("Objects are different.\n");
  }
}
By default (that is, with the --share_inlineable_strings option) both instances of the string literal use a single, shared, object:
armcc --share_inlineable_strings  --c99 test.c  -o-
Running the compiled image produces the following output:
String "abc" from getString() called directly is an object at address:          36812
String "abc" from getString() called using a pointer is an object at address:   36812
Objects are the same.
Compiling the same code with the --no_share_inlineable_strings option results in multiple string objects:
armcc --no_share_inlineable_strings  --c99 test.c  -o- 
Running the compiled image produces the following output:
String "abc" from getString() called directly is an object at address:          33004
String "abc" from getString() called using a pointer is an object at address:   36616
Objects are different.
Related reference
7.124 -Ospace
7.125 -Otime
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.