authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-15 21:47:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-16 03:01:13-07:00
log6a12dce207114842e2e49a3aeb18af01ab207f0b
tree6f98b79327ff2bf5205fbdc323a58f9d77435c5e
parent1530203c804db7e5abd7d6eac05cfbe449d30aea

glibc: fix some inconsistent flags with upstream

This more correctly matches what glibc does to build the objects inside libnonshared.a.

1 files changed, 72 insertions(+), 18 deletions(-)

src/glibc.zig+72-18
...@@ -272,22 +272,69 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -272,22 +272,69 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
272 const s = path.sep_str;272 const s = path.sep_str;
273 const linux_prefix = lib_libc_glibc ++273 const linux_prefix = lib_libc_glibc ++
274 "sysdeps" ++ s ++ "unix" ++ s ++ "sysv" ++ s ++ "linux" ++ s;274 "sysdeps" ++ s ++ "unix" ++ s ++ "sysv" ++ s ++ "linux" ++ s;
275 const deps = [_][]const u8{275 const Flavor = enum { nonshared, shared };
276 lib_libc_glibc ++ "stdlib" ++ s ++ "atexit.c",276 const Dep = struct { path: []const u8, flavor: Flavor };
277 lib_libc_glibc ++ "stdlib" ++ s ++ "at_quick_exit.c",277 const deps = [_]Dep{
278 linux_prefix ++ "stat.c",278 .{
279 linux_prefix ++ "fstat.c",279 .path = lib_libc_glibc ++ "stdlib" ++ s ++ "atexit.c",
280 linux_prefix ++ "lstat.c",280 .flavor = .nonshared,
281 linux_prefix ++ "stat64.c",281 },
282 linux_prefix ++ "fstat64.c",282 .{
283 linux_prefix ++ "lstat64.c",283 .path = lib_libc_glibc ++ "stdlib" ++ s ++ "at_quick_exit.c",
284 linux_prefix ++ "fstatat.c",284 .flavor = .nonshared,
285 linux_prefix ++ "fstatat64.c",285 },
286 linux_prefix ++ "mknodat.c",286 .{
287 lib_libc_glibc ++ "io" ++ s ++ "mknod.c",287 .path = linux_prefix ++ "stat.c",
288 lib_libc_glibc ++ "sysdeps" ++ s ++ "pthread" ++ s ++ "pthread_atfork.c",288 .flavor = .shared,
289 lib_libc_glibc ++ "debug" ++ s ++ "stack_chk_fail_local.c",289 },
290 lib_libc_glibc ++ "csu" ++ s ++ "errno.c",290 .{
291 .path = linux_prefix ++ "fstat.c",
292 .flavor = .shared,
293 },
294 .{
295 .path = linux_prefix ++ "lstat.c",
296 .flavor = .shared,
297 },
298 .{
299 .path = linux_prefix ++ "stat64.c",
300 .flavor = .shared,
301 },
302 .{
303 .path = linux_prefix ++ "fstat64.c",
304 .flavor = .shared,
305 },
306 .{
307 .path = linux_prefix ++ "lstat64.c",
308 .flavor = .shared,
309 },
310 .{
311 .path = linux_prefix ++ "fstatat.c",
312 .flavor = .shared,
313 },
314 .{
315 .path = linux_prefix ++ "fstatat64.c",
316 .flavor = .shared,
317 },
318 .{
319 .path = linux_prefix ++ "mknodat.c",
320 .flavor = .shared,
321 },
322 .{
323 .path = lib_libc_glibc ++ "io" ++ s ++ "mknod.c",
324 .flavor = .shared,
325 },
326 .{
327 .path = lib_libc_glibc ++ "sysdeps" ++ s ++ "pthread" ++ s ++ "pthread_atfork.c",
328 .flavor = .nonshared,
329 },
330 .{
331 .path = lib_libc_glibc ++ "debug" ++ s ++ "stack_chk_fail_local.c",
332 .flavor = .nonshared,
333 },
334 .{
335 .path = lib_libc_glibc ++ "csu" ++ s ++ "errno.c",
336 .flavor = .shared,
337 },
291 };338 };
292339
293 var c_source_files: [deps.len]Compilation.CSourceFile = undefined;340 var c_source_files: [deps.len]Compilation.CSourceFile = undefined;
...@@ -298,12 +345,19 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -298,12 +345,19 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
298 "-std=gnu11",345 "-std=gnu11",
299 "-fgnu89-inline",346 "-fgnu89-inline",
300 "-fmerge-all-constants",347 "-fmerge-all-constants",
348 "-frounding-math",
301 "-fno-stack-protector",349 "-fno-stack-protector",
350 "-fno-common",
302 "-fmath-errno",351 "-fmath-errno",
303 "-ftls-model=initial-exec",352 "-ftls-model=initial-exec",
304 "-Wno-ignored-attributes",353 "-Wno-ignored-attributes",
305 });354 });
306 try add_include_dirs(comp, arena, &args);355 try add_include_dirs(comp, arena, &args);
356
357 const shared_def = switch (dep.flavor) {
358 .shared => "-DSHARED",
359 .nonshared => "-DLIBC_NONSHARED=1",
360 };
307 try args.appendSlice(&[_][]const u8{361 try args.appendSlice(&[_][]const u8{
308 "-D_LIBC_REENTRANT",362 "-D_LIBC_REENTRANT",
309 "-include",363 "-include",
...@@ -313,11 +367,11 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -313,11 +367,11 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
313 "-include",367 "-include",
314 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),368 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),
315 "-DPIC",369 "-DPIC",
316 "-DLIBC_NONSHARED=1",370 shared_def,
317 "-DTOP_NAMESPACE=glibc",371 "-DTOP_NAMESPACE=glibc",
318 });372 });
319 c_source_files[i] = .{373 c_source_files[i] = .{
320 .src_path = try lib_path(comp, arena, dep),374 .src_path = try lib_path(comp, arena, dep.path),
321 .extra_flags = args.items,375 .extra_flags = args.items,
322 };376 };
323 }377 }