title: scanf produces segfault when the program is run with a custom entry point (using gcc 7.4.0)
body: <p>Consider the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      printf("main\n");
      int a;
      scanf("%d", &amp;a);
      printf("a = %d\n", a);
      return 0;
  }
  
  int main1() {
      printf("main1\n");
      int a;
      scanf("%d", &amp;a);
      printf("a = %d\n", a);
      exit(0);
      return 0;
  }
  
  int main2() {
      printf("main2\n");
      int a = getchar() - '0';
      int b = getchar() - '0';
      int c = getchar() - '0';
      printf("a = %d\n", 100 * a + 10 * b + c);
      exit(0);
      return 0;
  }
  </code></pre>
  
  <p>Assuming that the code resides in a file called test.c, the following works fine (it prints "a = 123"):</p>
  
  <pre><code>gcc -o test test.c
  echo 123 | ./test
  </code></pre>
  
  <p>If, however, I run the program with a custom entry point, I get the dreaded Segmentation fault:</p>
  
  <pre><code>gcc -o test test.c -e"main1"
  echo 123 | ./test
  </code></pre>
  
  <p>But if I replace the scanf with three getchars, the program runs fine again despite being run with a custom entry point:</p>
  
  <pre><code>gcc -o test test.c -e"main2"
  echo 123 | ./test
  </code></pre>
  
  <p>To make things even more interesting, these problems occur with gcc 7.4.0 but not with gcc 4.8.4.</p>
  
  <p>Any ideas?</p>