[XDCTOOLS-234] Rework preprocessor checks to support TI LLVM (clang)
diff --git a/src/packages/xdc/runtime/Reset.xdt b/src/packages/xdc/runtime/Reset.xdt
index af29b61..9148b85 100644
--- a/src/packages/xdc/runtime/Reset.xdt
+++ b/src/packages/xdc/runtime/Reset.xdt
@@ -1,11 +1,11 @@
 %%{
 /* --COPYRIGHT--,ESD
- *  Copyright (c) 2008 Texas Instruments. All rights reserved. 
- *  This program and the accompanying materials are made available under the 
+ *  Copyright (c) 2008-2018 Texas Instruments Incorporated
+ *  This program and the accompanying materials are made available under the
  *  terms of the Eclipse Public License v1.0 and Eclipse Distribution License
  *  v. 1.0 which accompanies this distribution. The Eclipse Public License is
  *  available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse
- *  Distribution License is available at 
+ *  Distribution License is available at
  *  http://www.eclipse.org/org/documents/edl-v10.php.
  *
  *  Contributors:
@@ -29,7 +29,7 @@
         }
     }
 %%}
-/* 
+/*
  * Startup_reset__I is an internal entry point called by target/platform
  * boot code. Boot code is not brought into a partial-link assembly. So,
  * without this pragma, whole program optimizers would otherwise optimize-out
@@ -41,9 +41,13 @@
 
 #ifdef __GNUC__
 #if __GNUC__ >= 4
+#ifdef __llvm__
+xdc_Void xdc_runtime_Startup_reset__I(void) __attribute__ ((used));
+#else
 xdc_Void xdc_runtime_Startup_reset__I(void) __attribute__ ((externally_visible));
 #endif
 #endif
+#endif
 
 %for (var i = 0; i < cnames.length; i++) {
 extern xdc_Void `cnames[i]`(void);  /* user defined reset function */
diff --git a/src/packages/xdc/runtime/Startup.xdt b/src/packages/xdc/runtime/Startup.xdt
index aaba2d2..b32bf58 100644
--- a/src/packages/xdc/runtime/Startup.xdt
+++ b/src/packages/xdc/runtime/Startup.xdt
@@ -1,11 +1,11 @@
 %%{
 /* --COPYRIGHT--,ESD
- *  Copyright (c) 2008 Texas Instruments. All rights reserved. 
- *  This program and the accompanying materials are made available under the 
+ *  Copyright (c) 2008-2018 Texas Instruments Incorporated
+ *  This program and the accompanying materials are made available under the
  *  terms of the Eclipse Public License v1.0 and Eclipse Distribution License
  *  v. 1.0 which accompanies this distribution. The Eclipse Public License is
  *  available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse
- *  Distribution License is available at 
+ *  Distribution License is available at
  *  http://www.eclipse.org/org/documents/edl-v10.php.
  *
  *  Contributors:
@@ -62,7 +62,7 @@
 }
 %}
 
-/* 
+/*
  * Startup_exec__I is an internal entry point called by target/platform
  * boot code. Boot code is not brought into a partial-link assembly. So,
  * without this pragma, whole program optimizers would otherwise optimize-out
@@ -74,9 +74,13 @@
 
 #ifdef __GNUC__
 #if __GNUC__ >= 4
+#ifdef __llvm__
+xdc_Void xdc_runtime_Startup_exec__I(void) __attribute__ ((used));
+#else
 xdc_Void xdc_runtime_Startup_exec__I(void) __attribute__ ((externally_visible));
 #endif
 #endif
+#endif
 
 /*
  *  ======== xdc_runtime_Startup_exec__I ========
diff --git a/src/packages/xdc/services/intern/gen/Config.java b/src/packages/xdc/services/intern/gen/Config.java
index 306c7dc..cb6b411 100644
--- a/src/packages/xdc/services/intern/gen/Config.java
+++ b/src/packages/xdc/services/intern/gen/Config.java
@@ -1,5 +1,5 @@
 /* --COPYRIGHT--,EPL
- *  Copyright (c) 2008 Texas Instruments and others.
+ *  Copyright (c) 2008-2018 Texas Instruments Incorporated
  *  All rights reserved. This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
@@ -1846,8 +1846,12 @@
             glob.out.printf("#pragma location = \".data_%1Module__state__V\"\n",
                 cname);
             glob.out.printf("#endif\n");
+            glob.out.printf("#if defined(__llvm__) && defined(__ti__)\n");
+            glob.out.printf("%1Module_State__ %1Module__state__V "
+                + "__attribute__ ((section(\".data:%1Module__state__V\")));\n",
+                cname);
             /* section placement for GCC except MacOS (see genArr comments) */
-            glob.out.printf("#if defined(__GNUC__) && !(defined(__MACH__) && defined(__APPLE__))\n");
+            glob.out.printf("#elif defined(__GNUC__) && !(defined(__MACH__) && defined(__APPLE__))\n");
             glob.out.printf("#ifndef __TI_COMPILER_VERSION__\n");
             glob.out.printf("%1Module_State__ %1Module__state__V "
                 + "__attribute__ ((section(\".data_%1Module__state__V\")));\n",
@@ -2005,10 +2009,13 @@
         glob.genTitle("INITIALIZATION ENTRY POINT");
 
         glob.out.printf("extern int __xdc__init(void);\n");
-        glob.out.printf("#ifdef __GNUC__\n"
+        glob.out.printf("#ifdef __GNUC__\n");
+        glob.out.printf("#if defined(__llvm__) && defined(__ti__)\n");
+        glob.out.printf("%+%t__attribute__ ((used))\n%-");
+        glob.out.printf("#else\n"
             + "#ifndef __TI_COMPILER_VERSION__\n");
         glob.out.printf("%+%t__attribute__ ((externally_visible))\n%-");
-        glob.out.printf("#endif\n#endif\n");
+        glob.out.printf("#endif\n#endif\n#endif\n");
         glob.out.printf("__FAR__ int (* volatile __xdc__init__addr)(void) = &__xdc__init;\n");
         skip();
     }