tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Adding MKPIE support to cwrappers



			Hi tech-pkg@, (Jörg)

I just had a first look at how to get PKGSRC_MKPIE to play well with cwrappers: I came up with the patch attached.

There may be more elegant ways to do it; looking forward to your feedback!

Cheers & HTH,
--
khorben
Index: mk/cwrappers.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/cwrappers.mk,v
retrieving revision 1.27
diff -p -u -r1.27 cwrappers.mk
--- mk/cwrappers.mk	5 Oct 2016 12:46:43 -0000	1.27
+++ mk/cwrappers.mk	16 Apr 2017 19:48:15 -0000
@@ -88,6 +88,9 @@ generate-cwrappers:
 .  for alias in ${CWRAPPERS_ALIASES.${wrappee}}
 	${RUN}ln -s ${CWRAPPERS_SRC_DIR}/${CWRAPPERS_CONFIG.${wrappee}}-wrapper ${WRAPPER_BINDIR}/${alias}
 .  endfor
+. if ${_PKGSRC_MKPIE} == "yes"
+	${RUN}echo mkpie=1 >> ${CWRAPPERS_CONFIG_DIR}/${CWRAPPERS_CONFIG.${wrappee}}
+. endif
 .endfor
 
 PREPEND_PATH+=		${WRAPPER_BINDIR}
Index: pkgtools/cwrappers/files/bin/common.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/cwrappers/files/bin/common.c,v
retrieving revision 1.6
diff -p -u -r1.6 common.c
--- pkgtools/cwrappers/files/bin/common.c	9 Dec 2016 22:25:28 -0000	1.6
+++ pkgtools/cwrappers/files/bin/common.c	16 Apr 2017 19:48:17 -0000
@@ -49,6 +49,8 @@ char *exec_path;
 char *exec_name;
 char *wrksrc;
 int debug;
+int mkpie;
+enum wrapmode wrapmode;
 
 static struct arglist prepend_args = TAILQ_HEAD_INITIALIZER(prepend_args);
 static struct arglist append_args = TAILQ_HEAD_INITIALIZER(append_args);
@@ -246,6 +248,10 @@ parse_config(const char *wrapper)
 			debug = atoi(line + 6);
 			continue;
 		}
+		if (strncmp(line, "mkpie=", 6) == 0) {
+			mkpie = atoi(line + 6);
+			continue;
+		}
 	}
 
 	fclose(fp);
Index: pkgtools/cwrappers/files/bin/common.h
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/cwrappers/files/bin/common.h,v
retrieving revision 1.5
diff -p -u -r1.5 common.h
--- pkgtools/cwrappers/files/bin/common.h	27 Nov 2016 11:46:45 -0000	1.5
+++ pkgtools/cwrappers/files/bin/common.h	16 Apr 2017 19:48:17 -0000
@@ -43,6 +43,17 @@ extern char *exec_path;
 extern char *exec_name;
 extern char *wrksrc;
 extern int debug;
+extern int mkpie;
+
+enum wrapmode {
+	WRAPMODE_UNKNOWN = 0,
+	WRAPMODE_CC_PREPROCESS_ONLY,
+	WRAPMODE_CC_ASSEMBLE_ONLY,
+	WRAPMODE_CC_COMPILE_ONLY,
+	WRAPMODE_CC_LINK_SHARED
+};
+
+extern enum wrapmode wrapmode;
 
 TAILQ_HEAD(arglist, argument);
 
Index: pkgtools/cwrappers/files/bin/normalise-cc.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/cwrappers/files/bin/normalise-cc.c,v
retrieving revision 1.4
diff -p -u -r1.4 normalise-cc.c
--- pkgtools/cwrappers/files/bin/normalise-cc.c	15 Sep 2016 17:08:14 -0000	1.4
+++ pkgtools/cwrappers/files/bin/normalise-cc.c	16 Apr 2017 19:48:17 -0000
@@ -70,6 +70,22 @@ normalise_cc(struct arglist *args)
 	TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
 		if (arg->val[0] != '-')
 			continue;
+		if (strcmp(arg->val, "-E") == 0) {
+			wrapmode = WRAPMODE_CC_PREPROCESS_ONLY;
+			continue;
+		}
+		if (strcmp(arg->val, "-S") == 0) {
+			wrapmode = WRAPMODE_CC_ASSEMBLE_ONLY;
+			continue;
+		}
+		if (strcmp(arg->val, "-c") == 0) {
+			wrapmode = WRAPMODE_CC_COMPILE_ONLY;
+			continue;
+		}
+		if (strcmp(arg->val, "-shared") == 0) {
+			wrapmode = WRAPMODE_CC_LINK_SHARED;
+			continue;
+		}
 		if (strcmp(arg->val, "-Xlinker") == 0) {
 			if (arg2 == NULL)
 				errx(255, "Missing argument for %s", arg->val);
@@ -103,6 +119,11 @@ normalise_cc(struct arglist *args)
 		}
 	}
 
+	if (mkpie && wrapmode != WRAPMODE_CC_LINK_SHARED) {
+		arg = argument_new(xstrdup("-pie"));
+		TAILQ_INSERT_TAIL(args, arg, link);
+	}
+
 	TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
 		if (strcmp(arg->val, "-o") == 0) {
 			/* Output to stdout ("-") is explicitly valid. */


Home | Main Index | Thread Index | Old Index